Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = peripheral.wrap("left")
- core = peripheral.wrap("top")
- max = core.getMaxEnergyStored()
- monX, monY = mon.getSize()
- function clear()
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- end
- function title()
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(monX/2-5, 2)
- mon.write("Power Status")
- end
- function current()
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(monX/2-6, 6)
- mon.write("Current Stored")
- end
- function drawText(x, y, text, color_txt, color_bg)
- mon.setBackgroundColor(color_bg)
- mon.setTextColor(color_txt)
- mon.setCursorPos(x,y)
- mon.write(text)
- end
- function drawLine(x, y, length, size, color_bar)
- for yPos = y, y+size-1 do
- mon.setBackgroundColor(color_bar)
- mon.setCursorPos(x, yPos)
- mon.write(string.rep(" ", length))
- end
- end
- function drawProg(x, y, name, length, size, minVal, maxVal, color_bar, color_bg)
- drawLine(x, y, length, size, color_bg)
- local barSize = math.floor((minVal/maxVal)*length)
- drawLine(x, y, barSize, size, color_bar)
- local text = name.." "..math.floor((minVal/maxVal)*100).."%"
- if barSize > monX/2+#text/2 then
- drawText(monX/2-#text/2, y+size/2, text, colors.black, colors.green)
- elseif barSize > #text then
- drawText((x+barSize)-#text, y+size/2, text, colors.black, colors.green)
- else
- drawText(monX/2-#text/2+2, y+size/2, text, colors.black, colors.gray)
- end
- end
- clear()
- while true do
- stored = core.getEnergyStored()
- title()
- mon.setCursorPos(1,4)
- mon.write("---------------------------------------")
- current()
- drawProg(3, 7, stored , monX-4, 2, stored, max, colors.green, colors.gray)
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment