fi5hii

Untitled

May 11th, 2024
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 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. local redstoneSideON = "left" -- Define the side where the redstone is connected for ON
  5. local redstoneSideOFF = "right" -- Define the side where the redstone is connected for OFF
  6.  
  7. -- Open the modem to listen on channel 1
  8. modem.open(1)
  9.  
  10. -- Function to handle messages
  11. function handleMessage()
  12. while true do
  13. local event, side, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  14.  
  15. -- Check if the message is from computer_1
  16. if senderChannel == 1 then
  17. -- Check the message content
  18. if message == "ON" then
  19. -- Activate the ON redstone signal
  20. redstone.setOutput(redstoneSideON, true)
  21. sleep(5) -- Wait for 5 seconds
  22. redstone.setOutput(redstoneSideON, false) -- Deactivate the ON signal after 5 seconds
  23. elseif message == "OFF" then
  24. -- Activate the OFF redstone signal
  25. redstone.setOutput(redstoneSideOFF, true)
  26. sleep(5) -- Wait for 5 seconds
  27. redstone.setOutput(redstoneSideOFF, false) -- Deactivate the OFF 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