fi5hii

Untitled

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