Advertisement
largeNumberGoeshere

tankHalfFilled

May 23rd, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. -- if low energy buffer, output a redstone signal
  2.  
  3.  
  4. -- settings
  5. local outputSide = "left"   -- output restone signal to this side
  6. local tankSide = "front"    -- the tank must be on this side of the computer
  7.  
  8. local maxEn = 14000
  9.  
  10. local buffer = maxEn/2
  11. local defaultRsState = true
  12.  
  13. -- setup
  14. local gen = peripheral.wrap(tankSide)
  15.  
  16. while true do
  17.     sleep(1)        
  18.  
  19.     local energy = 0
  20.     local tankDetected = pcall(
  21.         function()
  22.             energy = gen.tanks()[1].amount
  23.         end
  24.     )
  25.         local enStr = tostring(energy).." / "..maxEn
  26.                        
  27.                        
  28.     if not tankDetected then
  29.         print(enStr..": no tank fluid detected (This can mean there is an empty tank, or no tank there)")
  30.     else
  31.                 term.clear()
  32.                 term.setCursorPos(1,1)
  33.  
  34.                
  35.                 if energy > buffer then
  36.                         -- buffer is full enough
  37.                         print(enStr..": over threshold")        
  38.  
  39.                         rs.setOutput(outputSide,defaultRsState)
  40.                 else
  41.                         --buffer is low
  42.                         print(enStr..": under threshold")
  43.                         rs.setOutput(outputSide, not defaultRsState)
  44.  
  45.                 end
  46.  
  47.     end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement