Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --State Controller
- --Consts--
- local floorChanger = 7
- local door1 = 8
- local door2 = 10
- peripheral.find("modem", rednet.open)
- local floor = 0
- local running = false
- string.startswith = function(self, str)
- return self:find('^' .. str) ~= nil
- end
- while true do
- local id, message = rednet.receive()
- if message == "elevatorRunning" then
- running = not running
- elseif message:startswith("changeFloor") then
- local requestedFloor0 = string.sub(message, 12, 13) == "0"
- if not running and ((requestedFloor0 and floor == 1) or (not requestedFloor0 and floor == 0)) then
- if floor == 0 then
- floor = 1
- rednet.send(door1, "closeDoor0")
- rednet.send(door2, "closeDoor0")
- else
- floor = 0
- rednet.send(door1, "closeDoor1")
- rednet.send(door2, "closeDoor1")
- end
- rednet.send(floorChanger, "flip")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment