Advertisement
DOGGYWOOF

Untitled

Jul 31st, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. -- Function to handle redstone control
  2. local function controlRedstone(side, action, duration)
  3. if side == "back" or side == "left" then
  4. if action == "on" then
  5. redstone.setOutput(side, true)
  6. elseif action == "off" then
  7. redstone.setOutput(side, false)
  8. if duration then
  9. sleep(duration) -- Wait for the specified duration
  10. redstone.setOutput(side, true) -- Turn it back on after the duration
  11. end
  12. end
  13. end
  14. end
  15.  
  16. -- Attach the modem
  17. local modem = peripheral.find("modem")
  18.  
  19. if not modem then
  20. print("No modem found. Please attach a modem.")
  21. return
  22. end
  23.  
  24. modem.open(1) -- Open channel 1 for communication
  25.  
  26. -- Initialize redstone to "on" on boot for both sides
  27. local sides = {"back", "left"}
  28. for _, side in ipairs(sides) do
  29. redstone.setOutput(side, true)
  30. end
  31.  
  32. -- Main loop to listen for messages
  33. while true do
  34. local event, side, senderChannel, receiverChannel, message, distance = os.pullEvent("modem_message")
  35.  
  36. -- Check if the message has the expected format
  37. if type(message) == "table" and message.action and message.side then
  38. controlRedstone(message.side, message.action, message.duration)
  39. end
  40. end
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement