Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local term = require("term")
- local event = require("event")
- local component = require("component")
- local gpu = component.gpu
- local modem = component.modem
- local button = require("buttonAPI")
- local ELEV_ADDRESS = "429c5ba9-6dda-4ceb-8f48-4043c06f4ad1"
- local ELEV_PORT = 3539
- local THIS_FLOOR = "Workshop (Ground Level)"
- local GREEN = 0x00AA00
- local GREYGREEN = 0x335033
- local GREY = 0x444444
- local BLUE = 0x0000AA
- modem.open(3538)
- modem.setStrength(100)
- local function eventFilter(id)
- return (id == "touch" or id == "modem_message")
- end
- local function noOpButtonHandler()
- end
- local function callButtonHandler()
- button.flash("CALL ELEVATOR", 0.1)
- modem.send(ELEV_ADDRESS, ELEV_PORT, THIS_FLOOR)
- end
- local function updateDisplay(status, targetFloor)
- term.setCursorBlink(false)
- button.clear()
- button.clearTable()
- local minX = 5
- local minY = 3
- local buttonHeight = 2
- local buttonWidth = 24
- if status == "arrived" then
- if targetFloor == THIS_FLOOR then
- button.setBaseColor(GREEN)
- button.setTable("BOARD WHEN READY" , noOpButtonHandler, minX, minX + buttonWidth, minY, minY + buttonHeight)
- button.screen()
- button.heading("Elevator is Here")
- else
- button.setBaseColor(BLUE)
- button.setTable("CALL ELEVATOR" , callButtonHandler, minX, minX + buttonWidth, minY, minY + buttonHeight)
- button.screen()
- button.heading("At floor: ".. targetFloor)
- end
- elseif status == "onroute" then
- if targetFloor == THIS_FLOOR then
- button.setBaseColor(GREYGREEN)
- button.setTable("ON ROUTE" , noOpButtonHandler, minX, minX + buttonWidth, minY, minY + buttonHeight)
- button.screen()
- button.heading("Elevator has been called")
- else
- button.setBaseColor(GREY)
- button.setTable("ELEVATOR IN MOTION" , noOpButtonHandler, minX, minX + buttonWidth, minY, minY + buttonHeight)
- button.screen()
- button.heading("Moving to: "..targetFloor)
- end
- end
- end
- local function getClickOrUpdate()
- local e, _, x, y, _, status, targetFloor = event.pullFiltered(1,eventFilter)
- if e == "touch" then
- if x == nil or y == nil then
- local h, w = gpu.getResolution()
- gpu.set(h,w,".")
- gpu.set(h,w," ")
- else
- button.checkxy(x,y)
- end
- elseif e == "modem_message" then
- updateDisplay(status, targetFloor)
- end
- end
- function mainTouch()
- gpu.setResolution(34, 7)
- updateDisplay("arrived", "???")
- while(true) do
- getClickOrUpdate()
- end
- end
- mainTouch()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement