Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Elevator Program
- local elevatorPosition;
- term.clear();
- term.setCursorPos(1,1);
- local canLower = true;
- local elevatorStatus = "Idle";
- local protocol = "API";
- local chat = peripheral.wrap("left");
- rednet.host(protocol, "elevator");
- rednet.open("top");
- function lowerElevator()
- redstone.setOutput("right", true)
- elevatorPosition = 0;
- end
- function raiseElevator()
- redstone.setOutput("right", false)
- elevatorPosition = 1;
- end
- function checkInput()
- return redstone.getInput("bottom");
- end
- print("Starting Elevator System.");
- print("Raising Elevator...")
- raiseElevator();
- sleep(15)
- function checkForMessage()
- while true do
- local from, message = rednet.receive(protocol);
- if message == "lowerElevator" and canLower then
- canLower = false;
- print("Recieved Signal");
- print("Elevator Currently on Upper Level. Lowering...")
- elevatorStatus = "Lowering...";
- lowerElevator()
- sleep(13);
- print("Elevator Lowered to bottom level. Will Raise in 5 Seconds...")
- elevatorStatus = "Waiting...";
- sleep(5);
- elevatorStatus = "Raising...";
- print("Raising Elevator.")
- raiseElevator();
- sleep(13);
- canLower = true;
- elevatorStatus = "Idle";
- end
- end
- end
- function api()
- while true do
- local from, message = rednet.receive(protocol);
- if message == "getData" then
- rednet.send(from, elevatorStatus, protocol);
- end
- end
- end
- function checkForChat()
- while true do
- local _, name, chat = os.pullEvent("chat");
- if chat == "elevator" and canLower then
- canLower = false;
- print("Recieved Signal");
- print("Elevator Currently on Upper Level. Lowering...")
- elevatorStatus = "Lowering...";
- lowerElevator()
- sleep(13);
- print("Elevator Lowered to bottom level. Will Raise in 5 Seconds...")
- elevatorStatus = "Waiting...";
- sleep(5);
- print("Raising Elevator.")
- elevatorStatus = "Raising...";
- raiseElevator();
- sleep(13);
- canLower = true;
- elevatorStatus = "Idle";
- end
- end
- end
- function checkForRedstone()
- while true do
- if checkInput() == true and canLower then
- if elevatorPosition == 1 then
- canLower = false;
- print("Recieved Signal");
- print("Elevator Currently on Upper Level. Lowering...")
- elevatorStatus = "Lowering...";
- lowerElevator()
- sleep(13);
- print("Elevator Lowered to bottom level. Will Raise in 5 Seconds...")
- elevatorStatus = "Waiting...";
- sleep(5);
- print("Raising Elevator.")
- elevatorStatus = "Raising...";
- raiseElevator();
- sleep(13);
- canLower = true;
- elevatorStatus = "Idle";
- end
- end
- sleep(0);
- end
- end
- parallel.waitForAny(checkForChat, checkForRedstone, api, checkForMessage);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement