Advertisement
Guest User

capmgr.lua

a guest
Oct 16th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.72 KB | None | 0 0
  1. local rs = component.proxy(component.list("redstone")())
  2.  
  3. local ceiling = 14      --/15
  4. local floor = 1
  5. local intervalSeconds = 10
  6. local capSide = 4       -- http://ocdoc.cil.li/api:sides
  7.  
  8. local rsLevel = 0
  9. local capLevel = 0
  10.  
  11.  
  12. function sleep(timeout)
  13.   local deadline = computer.uptime() + (timeout or 0)
  14.   repeat
  15.     computer.pullSignal(0)
  16.   until computer.uptime() >= deadline
  17. end
  18.  
  19.  
  20. while true do
  21.   capLevel = rs.getComparatorInput(capSide)
  22.   if capLevel >= ceiling then
  23.     rsLevel = 1
  24.   elseif capLevel <= floor then
  25.     rsLevel = 0
  26.   end
  27.   rs.setOutput(capSide, rsLevel)
  28. -- debug stuff
  29.   rs.setOutput(3, rsLevel)
  30.   rs.setOutput(5, capLevel)
  31.  
  32.   rs.setOutput(2, 1)
  33.   sleep(1)
  34.   rs.setOutput(2, 0)
  35. -- end debug
  36.   sleep(intervalSeconds)
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement