hilburn

Power Monitor

Dec 18th, 2014
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.70 KB | None | 0 0
  1. function populateCells(cellList)
  2.     local periphList = peripherals.getNames()
  3.     cellList = {}
  4.     for i = 1, #periphList do
  5.         if peripheral.getType(periphList[i]) == "energy_cell" then --This might not actually be the name of the peripheral
  6.             cellList.insert(peripheral.wrap(periphList[i]))
  7.         end
  8.     end
  9.     return cellList
  10. end
  11.  
  12. function queryCells(cellList)
  13.     local power = 0
  14.     for _,v in ipairs(cellList) do
  15.         power = power + v.getEnergyStored() --this might not actually be the right function
  16.     end
  17.     return power
  18. end
  19.  
  20. function mainLoop()
  21.     local cellList
  22.     populateCells(cellList)
  23.     while true do
  24.         local power = queryCells(cellList)
  25.         --Display things on a monitor
  26.         sleep(5)
  27.     end
  28. end
  29.  
  30. mainLoop()
Advertisement
Add Comment
Please, Sign In to add comment