adds generatorControl
This commit is contained in:
parent
7608b3d0df
commit
d6d2324863
3
generatorControl/readme.md
Normal file
3
generatorControl/readme.md
Normal 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.
|
35
generatorControl/startup.lua
Normal file
35
generatorControl/startup.lua
Normal 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
|
Loading…
Reference in New Issue
Block a user