adds generatorControl

This commit is contained in:
Finn Dane 2023-09-01 00:13:49 +02:00
parent 7608b3d0df
commit d6d2324863
2 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# Generator Control
Monitors a battery and turns on a generator when the charge is below a configured ammount.
This was mainly developed to reduce constant noise.

View File

@ -0,0 +1,35 @@
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