Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Adjust as needed for your setup:
- --Modem
- local modemSide = "top"
- --Bundled Cable
- local cableSide = "bottom"
- --Code starts here
- rednet.open(modemSide)
- local floorsFile = "floors.txt"
- function loadFloors()
- if not fs.exists(floorsFile) then
- return {}
- else
- local file = fs.open(floorsFile, "r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- end
- function findFloor(cable)
- local floors = loadFloors()
- for _, floor in ipairs(floors) do
- if cable == floor.col then
- return floor
- end
- end
- return {num = "--", name = "Moving", col = 0}
- end
- function centerText(text, line)
- local width, height = term.getSize()
- term.setCursorPos((width - string.len(text)) / 2, line)
- print(text)
- end
- function displayUI()
- term.clear()
- centerText("Monitoring Elevator", 1)
- centerText("Current Floor", 4)
- end
- displayUI() -- Initial UI setup
- while true do
- local cable = rs.getBundledInput(cableSide)
- local floor = findFloor(cable)
- rednet.broadcast(floor, "ElevatorFloor")
- -- Update the current floor display
- term.setCursorPos(1, 6) -- Adjust Y to match layout
- term.clearLine()
- centerText(floor.num .. " - " .. floor.name, 6)
- sleep(.5) -- Adjust sleep time as needed
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement