Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Load the required components
- local monitor = peripheral.find("monitor", function(name) return name == "monitor_3" end) -- Monitor peripheral named monitor_3
- local modem = peripheral.wrap("back") -- Wrap the modem peripheral (assuming it's on the back of the computer)
- -- Function to display the texts on the monitor
- local function displayTexts()
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.setTextColor(colors.green)
- monitor.write("ON")
- monitor.setCursorPos(10, 1)
- monitor.setTextColor(colors.red)
- monitor.write("OFF")
- end
- -- Function to handle monitor touch events
- local function handleTouch(x, y)
- if y == 1 then
- if x >= 1 and x <= 2 then
- -- Send ON message to computer_4
- modem.transmit(4, 1, "ON")
- print("Signal sent: ON")
- elseif x >= 10 and x <= 12 then
- -- Send OFF message to computer_4
- modem.transmit(4, 1, "OFF")
- print("Signal sent: OFF")
- end
- end
- end
- -- Main function
- local function main()
- -- Display the texts
- displayTexts()
- while true do
- -- Wait for touch event
- local event, side, x, y = os.pullEvent("monitor_touch")
- handleTouch(x, y)
- end
- end
- -- Run the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment