fi5hii

Untitled

May 11th, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. -- Load the required components
  2. local monitor = peripheral.find("monitor", function(name) return name == "monitor_2" end) -- Monitor peripheral named monitor_2
  3. local redstoneSide = "left" -- Define the side where the redstone is connected
  4. local redstoneTop = "top" -- Define the side where the redstone is connected
  5.  
  6. -- Function to display line 1 from create_target_1 on monitor_2
  7. function displayLine()
  8. -- Get the line 1 from create_target_1
  9. local line = peripheral.call("create_target_1", "getLine", 1)
  10.  
  11. -- Clear the monitor
  12. monitor.clear()
  13.  
  14. -- Set cursor position at (1,1)
  15. monitor.setCursorPos(1, 1)
  16.  
  17. -- Display the line on monitor
  18. monitor.write(line)
  19.  
  20. -- Display clickable text below the line
  21. monitor.setCursorPos(1, 3)
  22. monitor.setTextColor(colors.green) -- Set text color to green
  23. monitor.write("ON")
  24. monitor.setTextColor(colors.red) -- Set text color to red
  25. monitor.write(" OFF")
  26. monitor.setTextColor(colors.white)
  27. end
  28.  
  29. -- Function to handle monitor touch events
  30. function handleTouch(x, y)
  31. -- Check if touch is within the clickable area for ON
  32. if y == 3 and x >= 1 and x <= 28 then
  33. -- Send a 5-second redstone pulse on the left side
  34. redstone.setOutput(redstoneSide, true)
  35. sleep(5)
  36. redstone.setOutput(redstoneSide, false)
  37. end
  38.  
  39. -- Check if touch is within the clickable area for OFF
  40. if y == 3 and x >= 33 and x <= 42 then
  41. -- Send a 5-second redstone pulse on the top side
  42. redstone.setOutput(redstoneTop, true)
  43. sleep(5)
  44. redstone.setOutput(redstoneTop, false)
  45. end
  46. end
  47.  
  48. -- Main function
  49. function main()
  50. while true do
  51. displayLine()
  52. -- Wait for touch event
  53. local event, side, x, y = os.pullEvent("monitor_touch")
  54. handleTouch(x, y)
  55. end
  56. end
  57.  
  58. -- Run the main function
  59. main()
  60.  
Advertisement
Add Comment
Please, Sign In to add comment