Advertisement
Mojokojo69

test

Aug 30th, 2023
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. local logo = {
  2. " ___ ",
  3. " / _ \\ ",
  4. " / , _/",
  5. "/_/|_/"
  6. }
  7.  
  8. print("Enter the modem channel:")
  9. local channel = tonumber(read())
  10.  
  11. print("Enter the current floor:")
  12. local currentFloor = tonumber(read())
  13.  
  14. local modem = peripheral.find("modem")
  15. local monitorFront = peripheral.wrap("front")
  16.  
  17. monitorFront.setTextScale(1)
  18. monitorFront.setTextColour(colours.green)
  19.  
  20. local lastButtonPress = 0
  21. local cooldown = 2 -- 2-second cooldown
  22.  
  23. local idleSent = false
  24.  
  25. local function refreshFrontMonitor()
  26. monitorFront.clear()
  27. monitorFront.setCursorPos(1, 1)
  28. end
  29.  
  30. local function displayKeypad(monitor)
  31. monitor.clear()
  32. monitor.setTextColour(colours.white)
  33. monitor.setCursorPos(2, 2)
  34. monitor.write("1")
  35. monitor.setCursorPos(6, 2)
  36. monitor.write("2")
  37. monitor.setCursorPos(10, 2)
  38. monitor.write("3")
  39. monitor.setCursorPos(2, 6)
  40. monitor.write("4")
  41. monitor.setCursorPos(6, 6)
  42. monitor.write("5")
  43. monitor.setCursorPos(10, 6)
  44. monitor.write("6")
  45. monitor.setCursorPos(2, 10)
  46. monitor.write("7")
  47. monitor.setCursorPos(6, 10)
  48. monitor.write("8")
  49. monitor.setCursorPos(10, 10)
  50. monitor.write("9")
  51. monitor.setCursorPos(6, 14)
  52. monitor.write("0")
  53. end
  54.  
  55. local function handleTouch(side, x, y)
  56. local currentTime = os.epoch("utc")
  57. if currentTime - lastButtonPress >= cooldown * 1000 then
  58. if side == "front" then
  59. local key = nil
  60. if x >= 2 and x <= 4 then
  61. if y == 2 then
  62. key = 1
  63. elseif y == 6 then
  64. key = 4
  65. elseif y == 10 then
  66. key = 7
  67. end
  68. elseif x >= 6 and x <= 8 then
  69. if y == 2 then
  70. key = 2
  71. elseif y == 6 then
  72. key = 5
  73. elseif y == 10 then
  74. key = 8
  75. elseif y == 14 then
  76. key = 0
  77. end
  78. elseif x >= 10 and x <= 12 then
  79. if y == 2 then
  80. key = 3
  81. elseif y == 6 then
  82. key = 6
  83. elseif y == 10 then
  84. key = 9
  85. end
  86. end
  87. if key then
  88. modem.transmit(channel, channel + 1, "key:" .. key)
  89. end
  90. end
  91. lastButtonPress = currentTime
  92. else
  93. print("Button press ignored due to cooldown.")
  94. end
  95. end
  96.  
  97. -- Initialize keypad
  98. displayKeypad(monitorFront)
  99.  
  100. -- Main loop
  101. while true do
  102. local event, side, x, y, senderChannel, replyChannel, message, senderDistance = os.pullEventRaw()
  103. local redstoneState = redstone.getInput("back")
  104. if event == "monitor_touch" then
  105. handleTouch(side, x, y)
  106. elseif redstoneState then
  107. if not idleSent then
  108. modem.transmit(channel, channel + 1, "idle")
  109. modem.transmit(channel, channel + 1, "elevator:" .. currentFloor)
  110. idleSent = true
  111. end
  112. end
  113. sleep(0.1)
  114. end
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement