Guest User

energy

a guest
Jul 12th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. power = peripheral.wrap("Induction Matrix_4")
  2. mon = peripheral.wrap("monitor_8")
  3.  
  4. local maxPower = 0
  5. local curPower = 0
  6. local perPower = 0
  7. local outPower = 0
  8. local inpPower = 0
  9. local capPower = 0
  10. monX,monY = mon.getSize()
  11.  
  12. function checkPower()
  13.   maxPower = power.getMaxEnergy()
  14.   curPower = power.getEnergy()
  15.   perPower = math.floor(((curPower/maxPower)*100)+0.5)
  16.   currentPower = math.floor(((curPower/2.5)/1000000)+0.5)
  17.  
  18.   outPower = power.getOutput()
  19.   inpPower = power.getInput()
  20.   capPower = power.getTransferCap()
  21.   outputPower = math.floor(((outPower/2.5)/1000)+0.5)
  22.   inputPower = math.floor(((inpPower/2.5)/1000)+0.5)
  23.   cappePower = math.floor(((capPower/2.5)/1000)+0.5)
  24. end
  25.  
  26.  
  27. function writeMon()
  28.   mon.setBackgroundColor(colors.black)
  29.   mon.clear()
  30.   mon.setCursorPos(1,1)
  31. --  mon.write("Power")
  32.   title = "  Power:" .. perPower .. "% Full  "
  33.   centerT(title, 1, colors.lightGray, colors.blue)
  34.   title = "  Stored Power:" .. currentPower .."Mrf "
  35.   centerT(title, 3, colors.lightGray, colors.blue)
  36.   title = "  Input:" .. inputPower .. "/" .. cappedPower .. "Krf"
  37.   centerT(title, 5, colors.lightGray, colors.blue)
  38.   title = "  Output:" .. outputPower .. "/" .. cappedPower .. "Krf"
  39.   centerT(title, 7, colors.lightGray, colors.blue)
  40.  
  41. end
  42.  
  43. function centerT(text,line,backColor,txtColor)
  44.   mon.setBackgroundColor(backColor)
  45.   mon.setTextColor(txtColor)
  46.   length = (string.len(text))
  47.   dif= math.floor(monX-length)
  48.   x = math.floor(dif/2)
  49.   mon.setCursorPos(x+1, line)
  50.   mon.write(text)
  51. end
  52.  
  53. function drawBar()
  54.   bar = math.floor(((curPower/maxPower)*(monX-2))+0.5)
  55.   mon.setCursorPos(2,monY-4)
  56.   mon.setBackgroundColor(colors.red)
  57.   mon.write(string.rep(" ", monX-2))
  58.  
  59. end
  60.  
  61. while true do
  62. checkPower()
  63. writeMon()
  64. drawBar()
  65.  
  66. print(curPower .. "/" .. maxPower)
  67. sleep(1)
  68. end
Advertisement
Add Comment
Please, Sign In to add comment