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_2" end) -- Monitor peripheral named monitor_2
- local redstoneSide = "left" -- Define the side where the redstone is connected
- local redstoneTop = "top" -- Define the side where the redstone is connected
- -- 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)
- end
- -- Function to handle monitor touch events
- function handleTouch(x, y)
- -- Check if touch is within the clickable area for ON
- if y == 3 and x >= 1 and x <= 28 then
- -- Send a 5-second redstone pulse on the left side
- redstone.setOutput(redstoneSide, true)
- sleep(5)
- redstone.setOutput(redstoneSide, false)
- end
- -- Check if touch is within the clickable area for OFF
- if y == 3 and x >= 33 and x <= 42 then
- -- Send a 5-second redstone pulse on the top side
- redstone.setOutput(redstoneTop, true)
- sleep(5)
- redstone.setOutput(redstoneTop, false)
- end
- end
- -- Main function
- function main()
- while true do
- displayLine()
- -- 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