Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sol = peripheral.wrap("top")
- local glass = peripheral.wrap("right")
- local batt = peripheral.wrap("back")
- --for graphing
- local posX = 15
- local posY = 50
- local offsetX = posX+5
- local offsetY = posY+5
- local sizeX = 40
- local sizeY = 180
- local backX = sizeX-10
- local backY = sizeY-10
- local function drawGraph(percent)
- --add frame
- glass.addBox(posX, posY, sizeX, sizeY, 0xFFFFFF, .5)
- --add background
- glass.addBox(offsetX, offsetY, backX, backY, 0x500000, .7)
- --determine vertical size of bar
- local size = backY * (percent/100)
- --determine vertical offset of bar
- local offset = offsetY + (backY-size)
- --add bar
- glass.addBox(offsetX, offset, backX, size, 0xEB0000, .7)
- end
- local function updateMain()
- local maxE = sol.getMaxEnergyStored()
- local currentE = sol.getEnergyStored()
- local percent
- if currentE <= 0 then
- percent = 0
- else
- percent = currentE/maxE * 100
- end
- glass.addText(1,40,"Solar Energy", 0xFFFFFF)
- drawGraph(percent)
- print("percent: ".. percent)
- end
- local function updateBackup()
- local maxE = batt.getMaxEnergyStored()
- local currentE = batt.getEnergyStored()
- local percent
- if currentE == maxE then
- updateMain()
- return
- else
- percent = currentE/maxE * 100
- end
- glass.addText(1,40,"Backup Energy", 0xFFFFFF)
- drawGraph(percent)
- end
- while true do
- sleep()
- glass.clear()
- updateBackup()
- glass.sync()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement