fi5hii

Untitled

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