Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("button")
- function setupMonitor()
- local monitor = peripheral.find("monitor")
- monitor.setBackgroundColor(colours.grey)
- monitor.clear()
- monitor.setCursorPos(1,1)
- return monitor
- end
- function monitorWrite(monitor, numOfButtons, openModem, currentFloor)
- button.setMonitor(monitor)
- local buttonList = createButtonList(monitor, numOfButtons)
- while true do
- local value = button.await(buttonList)
- if value ~= nil then
- print("sending to " .. value)
- openModem.transmit(6968, 0, value)
- end
- end
- end
- function createButtonList(monitor, numOfButtons)
- button.setMonitor(monitor)
- local buttonList = {}
- local pos = {0, 1}
- for i = 1, numOfButtons do
- local buttonMessage
- if pos[1] > 0 then
- pos[1] = pos[1] + 10
- else
- pos[1] = 6
- end
- if i < 10 then
- buttonMessage = ("Floor 0" .. i)
- else
- buttonMessage = ("Floor " .. i)
- end
- local newButton = button.create(buttonMessage)
- newButton.setPos(pos[1], pos[2])
- newButton.setColor(colours.lightGrey)
- newButton.setBlinkColor(colours.blue)
- newButton.onClickReturn(
- i
- )
- table.insert(buttonList, newButton)
- if i % 2 == 0 then
- pos = {0, pos[2]+2}
- end
- end
- return buttonList
- end
- --Start of script
- local numOfFloors
- if fs.exists("numOfFloors") then
- local file = fs.open("numOfFloors", "r")
- numOfFloors = textutils.unserialize(file.readAll())
- else
- print("Enter Number Of Floors")
- numOfFloors = read()
- local file = fs.open("numOfFloors", "w")
- file.write(textutils.serialize(numOfFloors))
- file.close()
- end
- local monitor = setupMonitor()
- local openModem = peripheral.find("modem") or error("No modem attached", 0)
- monitorWrite(monitor, numOfFloors, openModem)
Advertisement
Add Comment
Please, Sign In to add comment