Advertisement
Alexr360

SpeakFriend Hub

Mar 18th, 2024 (edited)
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. local function bastion()
  2.     local modem = peripheral.find("modem") or error("No modem attached", 0)
  3.     local name = "Archives"
  4.     modem.open(14) -- Open 43 so we can receive replies
  5.  
  6.     -- And wait for a reply
  7.     local event, side, channel, replyChannel, message, distance
  8.     repeat
  9.       event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  10.     until channel == 14
  11.  
  12.     -- Process the received message based on its content
  13.     if message == "1" then
  14.         print("Opening " .. name)
  15.         modem.transmit(42, 14, "Opening " .. name)
  16.         redstone.setOutput("left", true)  -- Emit a redstone signal to the right
  17.         os.sleep(1)  -- Keep the signal for 1 seconds
  18.         redstone.setOutput("left", false)  -- Turn off the redstone signal
  19.         print("Closing " .. name)
  20.         modem.transmit(42, 14, "Closing " .. name)
  21.     end
  22. end
  23.  
  24. term.clear()
  25. term.setCursorPos(1, 1)
  26. print("Speak friend and enter!")
  27.  
  28. -- Main loop
  29. while true do
  30.     bastion()
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement