Advertisement
Guest User

startup

a guest
Aug 26th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1,1)
  3.  
  4. modem = peripheral.wrap("back")
  5. modem.open(200)
  6.  
  7. waitList = {output1 = 0,output2 = 0,output3 = 0}
  8.  
  9. function ListenNetwork()
  10.   while true do
  11.     event, modemSide, sendingChannel, replyChannel, output, sendingDistance = os.pullEvent("modem_message")
  12.     event, modemSide, sendingChannel, replyChannel, duration, sendingDistance = os.pullEvent("modem_message")
  13.  
  14.     print("Received message from network")
  15.     print("Output : "..output)
  16.     print("Duration : "..duration)
  17.  
  18.     waitList["output"..output] = duration
  19.     port = 200+output
  20.     modem.transmit(port,port,"turn on")  
  21.   end
  22. end
  23.  
  24. function CountSeconds()
  25.   while true do
  26.    
  27.   i = 1
  28.  
  29.   print("Output 1 : "..waitList["output1"])
  30.   print("Output 2 : "..waitList["output2"])
  31.   print("Output 3 : "..waitList["output3"])
  32.   print("")
  33.  
  34.   while waitList["output"..i] ~= nil do
  35.     if waitList["output"..i] > 0 then
  36.       waitList["output"..i] = waitList["output"..i]-1    
  37.  
  38.       if waitList["output"..i] == 0 then
  39.         port = 200+i
  40.         modem.transmit(port,port,"turn off")
  41.         print("Turned off output :"..i)
  42.       end
  43.     end
  44.    
  45.     i = i+1
  46.   end
  47.  
  48.   sleep(1)
  49.   end
  50. end
  51.  
  52. parallel.waitForAll(ListenNetwork,CountSeconds)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement