fi5hii

Untitled

May 11th, 2024
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. -- Load the required components
  2. local modem = peripheral.find("wired_modem") -- Wired modem peripheral
  3. local redstone = peripheral.find("redstone") -- Redstone peripheral
  4.  
  5. -- Function to handle messages
  6. local function handleMessage()
  7. while true do
  8. local event, side, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  9.  
  10. -- Check if the message is from computer_3
  11. if senderChannel == 3 then
  12. -- Check the message content
  13. if message == "ON" then
  14. -- Activate the redstone signal on the left side
  15. redstone.setOutput("left", true)
  16. print("Signal received: ON")
  17. sleep(5) -- Wait for 5 seconds
  18. redstone.setOutput("left", false) -- Deactivate the redstone signal after 5 seconds
  19. elseif message == "OFF" then
  20. -- Activate the redstone signal on the right side
  21. redstone.setOutput("right", true)
  22. print("Signal received: OFF")
  23. sleep(5) -- Wait for 5 seconds
  24. redstone.setOutput("right", false) -- Deactivate the redstone signal after 5 seconds
  25. end
  26. end
  27. end
  28. end
  29.  
  30. -- Run the function to handle messages
  31. handleMessage()
  32.  
Advertisement
Add Comment
Please, Sign In to add comment