Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- batSide = "left"
- genSide = "back"
- setLevel = 1 --what % energy to turn genny on.
- resetLevel = 95 --what % energy to turn genny off.
- running = false
- mon = peripheral.wrap("monitor_0")
- bat = peripheral.wrap(batSide)
- maxEnergy = bat.getMaxEnergy()
- rs.setOutput(genSide, running)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- blinkState = false
- function doScreen(level)
- if running then blinkColor = colors.green else blinkColor = colors.red end
- mon.setTextColor(blinkColor)
- local lvl = (math.floor((level * 10) + 0.5))/10
- mon.setCursorPos(1,3)
- mon.write(" ")
- if lvl < 10 then mon.setCursorPos(3,3) else mon.setCursorPos(2,3) end
- mon.write(string.format("%.1f", lvl).."%")
- mon.setCursorPos(7,1)
- if blinkState then mon.setBackgroundColor(colors.black) else mon.setBackgroundColor(blinkColor) end
- mon.write(" ")
- if blinkState then
- blinkState = false
- else
- blinkState = true
- mon.setBackgroundColor(colors.black)
- end
- end
- while true do
- energy = bat.getEnergy()
- level = (energy / maxEnergy) * 100
- if running then
- if level >= resetLevel then
- running = false
- rs.setOutput(genSide, running)
- end
- else
- if level <= setLevel then
- running = true
- rs.setOutput(genSide, running)
- end
- end
- doScreen(level)
- local lvl = (math.floor((level * 1000) + 0.5))/1000
- print("Energy: "..energy.. "/"..maxEnergy.." Level:"..string.format("%.3f", lvl).."% Running:"..tostring(running))
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement