Advertisement
Guest User

energyDisplay.lua

a guest
Feb 18th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. rp = require("remotePeripherie")
  2. monitor = peripheral.find("monitor")
  3. local core = rp.wrap(15,"bottom")
  4.  
  5. local function niceNrString(n,m)
  6.   local metrics = {[0]="","k","M","G","T","P"}
  7.   local im = 0
  8.   while #(""..n) > 4 and (#metrics -1) > im do
  9.     n = math.floor(n/1000)
  10.     im = im + 1
  11.   end
  12.   return n.." "..metrics[im]..m
  13. end
  14.  
  15. local function toDisplay(m,a,b,c)
  16.   a = a or "--"
  17.   b = b or "--"
  18.   c = c or "--"
  19.   m = m or term
  20.  
  21.   m.clear()
  22.   m.setCursorPos(1,1)
  23.   m.write(""..a)
  24.   m.setCursorPos(1,2)
  25.   m.write(""..b)
  26.   m.setCursorPos(1,3)
  27.   m.write(""..c)
  28. end
  29.  
  30. while true do
  31.   local e = core.getEnergyStored()
  32.   local p = math.floor(100*e / core.getMaxEnergyStored())
  33.   local r = core.getTransferPerTick()
  34.   e = niceNrString(e,"rf")
  35.   p = p.." %"
  36.   r = niceNrString(r,"rf/t")
  37.   toDisplay(monitor, e, p, r)
  38.   sleep(5)
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement