from machine import Pin, SoftI2C
import ssd1306
import framebuf
import time
# using default address 0x3C
i2c = SoftI2C(sda=Pin(21), scl=Pin(22))
display = ssd1306.SSD1306_I2C(128, 64, i2c)
display.fill(0) # fill entire screen with colour=0
display.rect(10, 10, 111, 42, 1) # draw a rectangle outline 10,10 to width=111, height=42, colour=1
# draw battery percentage
x_pos = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110]
percentages = [.10, .20, .30, .40, .50, .60, .70, .80, .90, 1.0]
while True:
for ctr in range(10):
display.fill_rect(x_pos[ctr],11,10,40,1)
display.fill_rect(0,56,128,30,0)
display.text("{:.0%}".format(percentages[ctr]), 10, 56)
display.show()
time.sleep_ms(1000)
# This will clear the battery charge percentage
for ctr in range(10):
display.fill_rect(x_pos[ctr],11,10,40,0)
display.show()