Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local logo = {
- " ___ ",
- " / _ \\ ",
- " / , _/",
- "/_/|_/"
- }
- print("Enter the modem channel:")
- local channel = tonumber(read())
- print("Enter the current floor:")
- local currentFloor = tonumber(read())
- local modem = peripheral.find("modem")
- local monitorFront = peripheral.wrap("front")
- monitorFront.setTextScale(1)
- monitorFront.setTextColour(colours.green)
- local lastButtonPress = 0
- local cooldown = 2 -- 2-second cooldown
- local idleSent = false
- local function refreshFrontMonitor()
- monitorFront.clear()
- monitorFront.setCursorPos(1, 1)
- end
- local function displayKeypad(monitor)
- monitor.clear()
- monitor.setTextColour(colours.white)
- monitor.setCursorPos(2, 2)
- monitor.write("1")
- monitor.setCursorPos(6, 2)
- monitor.write("2")
- monitor.setCursorPos(10, 2)
- monitor.write("3")
- monitor.setCursorPos(2, 6)
- monitor.write("4")
- monitor.setCursorPos(6, 6)
- monitor.write("5")
- monitor.setCursorPos(10, 6)
- monitor.write("6")
- monitor.setCursorPos(2, 10)
- monitor.write("7")
- monitor.setCursorPos(6, 10)
- monitor.write("8")
- monitor.setCursorPos(10, 10)
- monitor.write("9")
- monitor.setCursorPos(6, 14)
- monitor.write("0")
- end
- local function handleTouch(side, x, y)
- local currentTime = os.epoch("utc")
- if currentTime - lastButtonPress >= cooldown * 1000 then
- if side == "front" then
- local key = nil
- if x >= 2 and x <= 4 then
- if y == 2 then
- key = 1
- elseif y == 6 then
- key = 4
- elseif y == 10 then
- key = 7
- end
- elseif x >= 6 and x <= 8 then
- if y == 2 then
- key = 2
- elseif y == 6 then
- key = 5
- elseif y == 10 then
- key = 8
- elseif y == 14 then
- key = 0
- end
- elseif x >= 10 and x <= 12 then
- if y == 2 then
- key = 3
- elseif y == 6 then
- key = 6
- elseif y == 10 then
- key = 9
- end
- end
- if key then
- modem.transmit(channel, channel + 1, "key:" .. key)
- end
- end
- lastButtonPress = currentTime
- else
- print("Button press ignored due to cooldown.")
- end
- end
- -- Initialize keypad
- displayKeypad(monitorFront)
- -- Main loop
- while true do
- local event, side, x, y, senderChannel, replyChannel, message, senderDistance = os.pullEventRaw()
- local redstoneState = redstone.getInput("back")
- if event == "monitor_touch" then
- handleTouch(side, x, y)
- elseif redstoneState then
- if not idleSent then
- modem.transmit(channel, channel + 1, "idle")
- modem.transmit(channel, channel + 1, "elevator:" .. currentFloor)
- idleSent = true
- end
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement