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 monitor = peripheral.find("monitor", function(name) return name == "monitor_2" end) -- Monitor peripheral named monitor_2
- local redstoneSide = "left" -- Define the side where the redstone is connected
- -- Check if modem exists
- if modem then
- -- Enable the modem
- modem.open(1) -- Open the modem on channel 1 to listen for messages
- end
- -- Function to display line 1 from create_target_1 on monitor_2
- function displayLine()
- -- Get the line 1 from create_target_1
- local line = peripheral.call("create_target_1", "getLine", 1)
- -- Clear the monitor
- monitor.clear()
- -- Set cursor position at (1,1)
- monitor.setCursorPos(1, 1)
- -- Display the line on monitor
- monitor.write(line)
- -- Display clickable text below the line
- monitor.setCursorPos(1, 3)
- monitor.setTextColor(colors.green) -- Set text color to green
- monitor.write("ON")
- monitor.setTextColor(colors.red) -- Set text color to red
- monitor.write(" OFF")
- monitor.setTextColor(colors.white)
- -- Return the hitbox coordinates for ON and OFF texts
- return 1, 2, 5, 8 -- x1, x2, x3, x4
- end
- -- Function to handle monitor touch events
- function handleTouch(x, y)
- local onX1, onX2, offX1, offX2 = displayLine()
- -- Check if touch is within the clickable area for ON
- if y == 3 and x >= onX1 and x <= onX2 then
- -- Send a message to computer_2 to activate the ON signal
- modem.transmit(2, 1, "ON")
- end
- -- Check if touch is within the clickable area for OFF
- if y == 3 and x >= offX1 and x <= offX2 then
- -- Send a message to computer_2 to activate the OFF signal
- modem.transmit(2, 1, "OFF")
- end
- end
- -- Main function
- function main()
- 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()
Add Comment
Please, Sign In to add comment