thislooksfun

Routing

Oct 15th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. rednet.open("front")
  2. rs.setOutput("top", false)
  3.  
  4. isTiming = false
  5. isGreen = rs.getInput("back")
  6. shouldOutput = false
  7. isPassthrough = false
  8. timer = nil
  9.  
  10. if isGreen then
  11.   rs.setOutput("top", true)
  12.   sleep(.1)
  13.   rs.setOutput("top", false)
  14. end
  15.  
  16. while true do
  17.   event = {os.pullEvent()}
  18.  
  19.   print("Event = "..event[1])
  20.  
  21.   if event[1] == "redstone" then
  22.     print("Redstone event")
  23.     if rs.getInput("front") then
  24.       isPassthrough = true
  25.     elseif not isTiming then
  26.       isPassthrough = false
  27.       print("Not timing")
  28.       if rs.getInput("left") then
  29.         print("Starting timer")
  30.         isTiming = true
  31.         timer = os.startTimer(16)
  32.         rednet.broadcast("15")
  33.       end
  34.     end
  35.    
  36.     isGreen = rs.getInput("back")
  37.     if isGreen then print("isGreen = true") else print("isGreen = false") end
  38.    
  39.    
  40.   elseif event[1] == "timer" then
  41.     print("Timer event")
  42.     if event[2] == timer then
  43.       print("Timer done")
  44.       isTiming = false
  45.       shouldOutput = true
  46.     end
  47.   end
  48.  
  49.   if isGreen then
  50.     if isPassthrough then
  51.       rs.setOutput("top", true)
  52.       sleep(1.5)
  53.       rs.setOutput("top", false)
  54.       isPassthrough = false
  55.     elseif shouldOutput then
  56.       rs.setOutput("top", true)
  57.       sleep(.1)
  58.       rs.setOutput("top", false)
  59.       shouldOutput = false
  60.     end
  61.   end
  62.   print("")
  63. end
Advertisement
Add Comment
Please, Sign In to add comment