Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modem = peripheral.wrap("right")
- monitor = peripheral.wrap("top")
- monitor.setTextScale(1)
- lastStoredEnergy = 0
- energyRate = 0
- timeEmpty = 0
- function comma_value(n) -- credit http://richard.warburton.it
- local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
- return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
- end
- function SecondsToClock(nSeconds)
- if nSeconds == 0 then
- return "00:00:00"
- elseif nSeconds > -math.huge and nSeconds < math.huge then
- numHours = math.floor(nSeconds/3600)
- numMins = string.format("%.2d", math.floor(nSeconds/60 - (numHours*60)))
- numSecs = string.format("%.2d", math.floor(nSeconds - numHours*3600 - numMins *60))
- return numHours..":"..numMins..":"..numSecs
- else
- return "n/a"
- end
- end
- while(true) do
- numCells = 0
- attachedCells = {}
- for index,value in pairs(modem.getNamesRemote()) do
- if string.find(value,'energycell',1,true) then
- numCells = numCells + 1
- attachedCells[numCells] = value
- end
- end
- for i = 1,12 do
- storedEnergy = 0
- maxStoredEnergy = 0
- for index,value in pairs(attachedCells) do
- storedEnergy = storedEnergy + modem.callRemote(value, "getEnergyStored","")
- maxStoredEnergy = maxStoredEnergy + modem.callRemote(value, "getMaxEnergyStored","")
- end
- percentStored = math.floor(100*storedEnergy/maxStoredEnergy)
- energyRate = lastStoredEnergy - storedEnergy
- timeEmpty = math.floor(storedEnergy/energyRate)
- monitor.clear()
- monitor.setCursorPos(2,1)
- monitor.write("Connected Cells: "..comma_value(numCells))
- monitor.setCursorPos(2,3)
- monitor.write("Stored Energy: "..comma_value(storedEnergy).." ("..percentStored.."%)")
- monitor.setCursorPos(2,4)
- monitor.write("Energy Use: "..comma_value(energyRate).."/s")
- monitor.setCursorPos(2,6)
- monitor.write("Time to Empty: "..SecondsToClock(timeEmpty))
- print(i)
- os.sleep(1)
- lastStoredEnergy = storedEnergy
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement