Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Elevator Call Button
- --Version 2.2
- local updateCode = "7EusNXVa";
- local elevatorNumberFile = fs.open("elevatorNumber.dat", "r"); --Gets the elevator number from file.
- local elevatorNumber = tonumber(elevatorNumberFile.readAll());
- elevatorNumberFile.close();
- local floorNumberFile = fs.open("floorNumber.dat", "r"); --Gets the floor number from file.
- local floorNumber = tonumber(floorNumberFile.readAll());
- floorNumberFile.close();
- local protocol = "ELEVATOR" .. elevatorNumber;
- local hostname = "callbutton" .. floorNumber;
- local elevatorController;
- local uptime = 0;
- while true do
- rednet.open("bottom");
- elevatorController = rednet.lookup(protocol, "elevator_controller");
- if elevatorController ~= nil then
- break;
- end
- end
- term.clear();
- term.setCursorPos(1,1);
- function update()
- shell.run("pastebin", "get", updateCode, "download");
- if fs.exists("download") then
- fs.delete("startup.lua");
- fs.copy("download", "startup.lua");
- fs.delete("download");
- return true;
- else
- return false;
- end
- end
- local status = "idle";
- function exit()
- error("Exiting Program.")
- end
- function formatTime() --Format seconds into readable time
- local days = math.floor(uptime/86400)
- local hours = math.floor((uptime % 86400)/3600)
- local minutes = math.floor((uptime % 3600)/60)
- local seconds = math.floor((uptime % 60))
- return string.format("%02d:%02d:%02d:%02d",days,hours,minutes,seconds)
- end
- function countTime() --Function keeping track of uptime.
- while true do
- uptime = uptime + 1;
- sleep(1);
- end
- end
- function log(inputText) --print out message with timestamp
- print("[" .. formatTime(uptime) .. "] " .. inputText);
- end
- function alertLight()
- redstone.setOutput("back", true);
- sleep(.5);
- redstone.setOutput("back", false);
- sleep(.5);
- end
- function mainLoop()
- while true do
- if status == "idle" then
- if redstone.getInput("back") == true then
- status = "active";
- rednet.send(elevatorController, floorNumber, protocol);
- end
- end
- sleep(.5);
- end
- end
- function network()
- rednet.host(protocol, hostname)
- log("Started.")
- while true do
- local from, message = rednet.receive(protocol);
- if message == "status" then
- log("Recieved Request for Status.")
- rednet.send(from, true, protocol);
- elseif message == "idle" then
- log("Recieved Request to set to idle")
- status = "idle";
- rednet.send(from, true, protocol);
- elseif message == "active" then
- log("Recieved Request to set to active")
- status = "active";
- rednet.send(from, true, protocol);
- elseif message == "update" then
- rednet.send(from, true, protocol);
- rednet.send(from, update(), protocol);
- os.reboot();
- elseif message == "restart" then
- os.reboot();
- end
- end
- end
- parallel.waitForAll(mainLoop, network, countTime);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement