Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1,1)
- modem = peripheral.wrap("back")
- modem.open(200)
- waitList = {output1 = 0,output2 = 0,output3 = 0}
- function ListenNetwork()
- while true do
- event, modemSide, sendingChannel, replyChannel, output, sendingDistance = os.pullEvent("modem_message")
- event, modemSide, sendingChannel, replyChannel, duration, sendingDistance = os.pullEvent("modem_message")
- print("Received message from network")
- print("Output : "..output)
- print("Duration : "..duration)
- waitList["output"..output] = duration
- port = 200+output
- modem.transmit(port,port,"turn on")
- end
- end
- function CountSeconds()
- while true do
- i = 1
- print("Output 1 : "..waitList["output1"])
- print("Output 2 : "..waitList["output2"])
- print("Output 3 : "..waitList["output3"])
- print("")
- while waitList["output"..i] ~= nil do
- if waitList["output"..i] > 0 then
- waitList["output"..i] = waitList["output"..i]-1
- if waitList["output"..i] == 0 then
- port = 200+i
- modem.transmit(port,port,"turn off")
- print("Turned off output :"..i)
- end
- end
- i = i+1
- end
- sleep(1)
- end
- end
- parallel.waitForAll(ListenNetwork,CountSeconds)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement