Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local storages = {
- peripheral.wrap("modular_accumulator_0"),
- peripheral.wrap("modular_accumulator_1")
- }
- local screen = peripheral.wrap("monitor_0")
- term.redirect(screen)
- term.clear()
- function centerText(text)
- local x, y = term.getSize()
- local x2, y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- screen.write(text)
- end
- function createProgressBar(storagePercentFormated)
- local fullBarLength = math.floor(storagePercentFormated / 10)
- local progressBar = ""
- for i = 1, fullBarLength do
- progressBar = progressBar .. "#"
- end
- for i = 1, 10 - fullBarLength do
- progressBar = progressBar .. " "
- end
- progressBar = "[" .. progressBar .. "]"
- return progressBar
- end
- function updateScreen(storage, index)
- screen.setCursorPos(1, 6 + index * 4)
- local storagePercent = storage.getPercent()
- local storageCapacity = storage.getCapacity()
- local storagePercentFormated = tonumber(string.format("%.1f", storagePercent))
- centerText("[[ Battery "..index.." ]]")
- screen.setCursorPos(1, 7 + index * 4)
- if (storagePercent >= 75) and (storagePercent <= 100) then
- screen.setTextColor(32)
- elseif (storagePercent >= 50) and (storagePercent < 75) then
- screen.setTextColor(16)
- elseif (storagePercent >= 0) and (storagePercent < 50) then
- screen.setTextColor(16384)
- end
- centerText(createProgressBar(storagePercentFormated.." "..storagePercentFormated.."%"))
- end
- while true do
- for index, storage in ipairs(storages) do
- updateScreen(storage, index)
- end
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement