Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Load the required components
- local modem = peripheral.find("modem") -- Modem peripheral
- local redstone = peripheral.find("redstone") -- Redstone peripheral
- local redstoneSideON = "left" -- Define the side where the redstone is connected for ON
- local redstoneSideOFF = "right" -- Define the side where the redstone is connected for OFF
- -- Open the modem to listen on channel 1
- modem.open(1)
- -- Function to handle messages
- function handleMessage()
- while true do
- local event, side, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
- -- Check if the message is from computer_1
- if senderChannel == 1 then
- -- Check the message content
- if message == "ON" then
- -- Activate the ON redstone signal
- redstone.setOutput(redstoneSideON, true)
- sleep(5) -- Wait for 5 seconds
- redstone.setOutput(redstoneSideON, false) -- Deactivate the ON signal after 5 seconds
- elseif message == "OFF" then
- -- Activate the OFF redstone signal
- redstone.setOutput(redstoneSideOFF, true)
- sleep(5) -- Wait for 5 seconds
- redstone.setOutput(redstoneSideOFF, false) -- Deactivate the OFF signal after 5 seconds
- end
- end
- end
- end
- -- Run the function to handle messages
- handleMessage()
Advertisement
Add Comment
Please, Sign In to add comment