fi5hii

Untitled

May 11th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. -- Load the required components
  2. local monitor = peripheral.find("monitor", function(name) return name == "monitor_3" end) -- Monitor peripheral named monitor_3
  3. local modem = peripheral.wrap("back") -- Wrap the modem peripheral (assuming it's on the back of the computer)
  4.  
  5. -- Function to display the texts on the monitor
  6. local function displayTexts()
  7. monitor.clear()
  8. monitor.setCursorPos(1, 1)
  9. monitor.setTextColor(colors.green)
  10. monitor.write("ON")
  11. monitor.setCursorPos(10, 1)
  12. monitor.setTextColor(colors.red)
  13. monitor.write("OFF")
  14. end
  15.  
  16. -- Function to handle monitor touch events
  17. local function handleTouch(x, y)
  18. if y == 1 then
  19. if x >= 1 and x <= 2 then
  20. -- Send ON message to computer_4
  21. modem.transmit(4, 1, "ON")
  22. print("Signal sent: ON")
  23. elseif x >= 10 and x <= 12 then
  24. -- Send OFF message to computer_4
  25. modem.transmit(4, 1, "OFF")
  26. print("Signal sent: OFF")
  27. end
  28. end
  29. end
  30.  
  31. -- Main function
  32. local function main()
  33. -- Display the texts
  34. displayTexts()
  35.  
  36. while true do
  37. -- Wait for touch event
  38. local event, side, x, y = os.pullEvent("monitor_touch")
  39. handleTouch(x, y)
  40. end
  41. end
  42.  
  43. -- Run the main function
  44. main()
  45.  
Advertisement
Add Comment
Please, Sign In to add comment