Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- elevator server
- local modem = peripheral.find("modem")
- local floor = 3 -- change this to whatever floor it is serving
- local channel = 10 + floor
- term.setCursorPos(1,1)
- term.clear()
- term.setCursorPos(1,1)
- print("floor " .. floor)
- print("port " .. channel)
- modem.open(channel)
- function callElevator()
- redstone.setOutput("top", true)
- os.sleep(0.025)
- redstone.setOutput("top", false)
- end
- function isElevatorDocked()
- return redstone.getInput("top")
- end
- function handleRequests()
- while true do
- local event, side, receivedChannel, replyChannel, message, distance = os.pullEvent("modem_message")
- if receivedChannel == channel then
- if message == "elevator_request" then
- callElevator()
- elseif message == "is_elevator_docked" then
- local status = isElevatorDocked()
- modem.transmit(replyChannel, channel, status)
- end
- end
- end
- end
- parallel.waitForAll(handleRequests)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement