Advertisement
popatop15

Tank Monitor

Apr 18th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. tank                    = peripheral.wrap('back')
  2. mon                     = peripheral.wrap('front')
  3. warning                 = 40
  4. warnPause               = 1
  5. pauseTime               = 2
  6.  
  7. local function centerText(text)
  8.   x,y = mon.getSize()
  9.   x1,y1 = mon.getCursorPos()
  10.   mon.setCursorPos((math.floor(x/2) - (math.floor(#text/2))), y1)
  11.   mon.write(text)  
  12. end
  13.  
  14. while true do
  15.  
  16.     mon.clear()
  17.  
  18.     amount   = tank.getTankInfo('back')[1].amount
  19.     capacity = tank.getTankInfo('back')[1].capacity
  20.  
  21.     if amount == nil then
  22.         amount = 0
  23.         percent = 0
  24.     else
  25.         percent = math.floor(((100 * amount / capacity) * 100) / 100)
  26.     end
  27.    
  28.     if amount < percent then
  29.         mon.setBackgroundColor(colors.red)
  30.         mon.clear()
  31.         mon.setCursorPos(1,3)
  32.         centerText("Alert")
  33.         pauseTime = warnPause
  34.         sleep(pauseTime)
  35.         mon.setBackgroundColor(colors.black)
  36.         mon.clear()
  37.     end
  38.  
  39.     mon.setCursorPos(1,1)
  40.     mon.write("Capacity: "..capacity.." mB")
  41.     mon.setCursorPos(1,2)
  42.     mon.write("Current:  "..amount.." mB") 
  43.     mon.setCursorPos(1,3)
  44.     mon.write("          "..percent.."%")
  45.  
  46.     sleep(pauseTime)
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement