Advertisement
RabaGhast

TankLiquidMonitor

Sep 24th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. local mon = peripheral.wrap("top")
  2. local tank = peripheral.wrap("right")
  3. local modem = peripheral.wrap("back")
  4. modem.open(100)
  5. local amount
  6. local cap
  7. local percentfull
  8. local warning = 10
  9. local sleepTime = 10
  10.  
  11.  
  12.  
  13. function getTank(tank)
  14.   local tableInfo = tank.getTankInfo("unknown")
  15.   fluidAmount = nil
  16.   fluidCapacity = tableInfo[1].capacity
  17.   local contents = tableInfo[1].contents  
  18.   if contents then
  19.     fluidAmount = contents.amount
  20.   end
  21.   return fluidAmount, fluidCapacity
  22. end
  23.  
  24. while true do
  25.   mon.clear()
  26.   mon.setCursorPos(3,3)
  27.   rs.setOutput("left", false)
  28.  
  29.   local fluidAmount, fluidCapacity = getTank(tank)
  30.   cap = fluidCapacity / 1000
  31.   amount = fluidAmount
  32.   mon.setTextColor(colours.white)
  33.  
  34.   if fluidCapacity == nil then
  35.     return
  36.   end
  37.  
  38.   if amount == nil then
  39.     amount = 0
  40.     percentfull = 0
  41.   else
  42.      amount = math.floor(amount / 1000)
  43.      percentfull = math.floor(100 * amount / cap)
  44.   end
  45.  
  46.   if percentfull < warning then
  47.      rs.setOutput("left", true)
  48.      mon.setTextColour(colours.red)
  49.   elseif percentfull > 90 then
  50.      mon.setTextColour(colours.green)
  51.   end
  52.   mon.write(percentfull.."%")
  53.   modem.transmit(100, 100, percentfull)
  54.   print(percentfull.."%")
  55.   sleep(sleepTime)
  56. end
  57. --ref: http://pastebin.com/XeHKVry4
  58. --RabaGhast
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement