fi5hii

Untitled

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