Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to handle redstone control
- local function controlRedstone(side, action, duration)
- if side == "back" or side == "left" then
- if action == "on" then
- redstone.setOutput(side, true)
- elseif action == "off" then
- redstone.setOutput(side, false)
- if duration then
- sleep(duration) -- Wait for the specified duration
- redstone.setOutput(side, true) -- Turn it back on after the duration
- end
- end
- end
- end
- -- Attach the modem
- local modem = peripheral.find("modem")
- if not modem then
- print("No modem found. Please attach a modem.")
- return
- end
- modem.open(1) -- Open channel 1 for communication
- -- Initialize redstone to "on" on boot for both sides
- local sides = {"back", "left"}
- for _, side in ipairs(sides) do
- redstone.setOutput(side, true)
- end
- -- Main loop to listen for messages
- while true do
- local event, side, senderChannel, receiverChannel, message, distance = os.pullEvent("modem_message")
- -- Check if the message has the expected format
- if type(message) == "table" and message.action and message.side then
- controlRedstone(message.side, message.action, message.duration)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement