36 lines
861 B
Lua
36 lines
861 B
Lua
|
local batterySide = "left"
|
||
|
local generatorSide = "bottom"
|
||
|
|
||
|
-- both 0.0 - 1.0
|
||
|
local lowPercent = 0.1
|
||
|
local highPercent = 0.9
|
||
|
|
||
|
|
||
|
local batt = peripheral.wrap(batterySide)
|
||
|
|
||
|
term.clear()
|
||
|
|
||
|
local percentage = nil
|
||
|
local delta = nil
|
||
|
local tempTime = nil
|
||
|
local prevTime = os.epoch("utc")
|
||
|
local prevVal = 0
|
||
|
while true do
|
||
|
tempTime = os.epoch("utc")
|
||
|
percentage = batt.getEnergyFilledPercentage()
|
||
|
delta = percentage - prevVal
|
||
|
prevVal = percentage
|
||
|
|
||
|
term.setCursorPos(1,1)
|
||
|
print(string.format("battery level: %05.2f%%", percentage*100))
|
||
|
print(string.format("delta: %+06.2f%% / %05.3fs", delta*100, (tempTime-prevTime)/1000))
|
||
|
prevTime = tempTime
|
||
|
|
||
|
if percentage < lowPercent then
|
||
|
redstone.setOutput(generatorSide, true)
|
||
|
elseif percentage > highPercent then
|
||
|
redstone.setOutput(generatorSide, false)
|
||
|
end
|
||
|
sleep(1)
|
||
|
end
|