diff --git a/generatorControl/readme.md b/generatorControl/readme.md new file mode 100644 index 0000000..8cace19 --- /dev/null +++ b/generatorControl/readme.md @@ -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. diff --git a/generatorControl/startup.lua b/generatorControl/startup.lua new file mode 100644 index 0000000..08f0d76 --- /dev/null +++ b/generatorControl/startup.lua @@ -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