import time, random, math
from machine import I2C, SoftI2C, Pin, RTC
from pico_i2c_lcd import I2cLcd
rtc = RTC()
rtc.datetime((2024, 2, 9, 5, 1, 0, 0, 0)) # set
# year, month, sdate, weekday, hour, min, sec, microsec
i2c = SoftI2C(sda=Pin(0), scl=Pin(1), freq=400000)
lcd_addr = i2c.scan()[0]
lcd = I2cLcd(i2c, lcd_addr, 2, 16)
print(rtc.datetime()) # get
# rtc.datetime can either get or set the clock
while True:
lcd.move_to(0, 0)
p = rtc.datetime()
ans = ""
for i in range(4, 7):
ans += str(p[i]) + ":"
lcd.putstr(ans)
time.sleep(1)
lcd.clear()