Advertisement
colhaydutu

lamp control

Aug 31st, 2023 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. local redstoneOutput = true
  2. local function findMonitors()
  3. local monitors = {}
  4. for _, name in pairs(peripheral.getNames()) do
  5. if string.match(name, "^monitor_") then
  6. local monitor = peripheral.wrap("right")
  7. table.insert(monitors, monitor)
  8. end
  9. end
  10. return monitors
  11. end
  12.  
  13. local monitors = findMonitors()
  14.  
  15. local monitor = monitors[1]
  16. local modem = peripheral.find("modem")
  17.  
  18.  
  19. local function drawBar()
  20. local w, h = monitor.getSize()
  21. term.redirect(monitor)
  22. paintutils.drawLine(3, 3, 4, 3, colors.cyan)
  23. paintutils.drawLine(16, 3, w - 2, 3, colors.cyan)
  24. paintutils.drawLine(3, 3, 3, h - 1, colors.cyan)
  25. paintutils.drawLine(w - 2, 3, w - 2, h - 1, colors.cyan)
  26. paintutils.drawLine(w - 2, h - 1, 3, h - 1, colors.cyan)
  27. paintutils.drawLine(6, 4, 14, 4, colors.lightGray)
  28. paintutils.drawLine(6, 3, 14, 3, colors.lightGray)
  29. paintutils.drawLine(6, 2, 14, 2, colors.lightGray)
  30. paintutils.drawLine(16, 2, 16, 4, colors.cyan)
  31. monitor.setBackgroundColor(colors.lightGray)
  32. monitor.setTextColor(colors.black)
  33. monitor.setCursorPos(7, 3)
  34. monitor.write("[LIGHT]")
  35. monitor.setBackgroundColor(colors.gray)
  36. end
  37.  
  38. drawBar()
  39.  
  40.  
  41.  
  42. while true do
  43. local event, side, x, y = os.pullEvent("monitor_touch")
  44. monitor.setBackgroundColor(colors.gray) -- Arka plan rengini gri olarak ayarla
  45.  
  46. if x >= 10 and x <= 19 and y >= 6 and y <= 8 then
  47. if redstoneOutput then
  48. paintutils.drawLine(9, 6, 20, 6, colors.green)
  49. paintutils.drawLine(9, 7, 20, 7, colors.green)
  50. paintutils.drawLine(9, 8, 20, 8, colors.green)
  51. monitor.setCursorPos(10, 7)
  52. monitor.setBackgroundColor(colors.green)
  53. monitor.setTextColor(colors.black)
  54. monitor.write(" [ ON ] ")
  55. redstone.setOutput("back", true)
  56. redstoneOutput = false
  57. else
  58. paintutils.drawLine(9, 6, 20, 6, colors.red)
  59. paintutils.drawLine(9, 7, 20, 7, colors.red)
  60. paintutils.drawLine(9, 8, 20, 8, colors.red)
  61. monitor.setCursorPos(10, 7)
  62. monitor.setBackgroundColor(colors.red)
  63. monitor.setTextColor(colors.black)
  64. monitor.write(" [ OFF ] ")
  65. redstone.setOutput("back", false)
  66. redstoneOutput = true
  67. end
  68. end
  69.  
  70. drawBar()
  71.  
  72. os.sleep(1)
  73. end
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement