from machine import Pin,I2C,SoftI2C
from ssd1306 import SSD1306_I2C
from ds1307 import DS1307
import time
i2c = I2C(0,scl = Pin(26),sda = Pin(27))
rtc = DS1307(i2c)
i2c = SoftI2C(scl=(17),sda=(16))
oled = SSD1306_I2C(128,64,i2c,addr=0x3c)
#格式:年,月,日,星期,时,分,秒
#rtc.datetime((2026,3,5,4,18,58,00,00))
oled.fill(0)
while True:
current_time = rtc.datetime()
year = current_time[0]
month = current_time[1]
day = current_time[2]
hour = current_time[4]
minute = current_time[5]
secend = current_time[6]
oled.text(f"{year:02d} {month:02d} {day:02d} ",30,24)
oled.text(f"{hour:02d}:{minute:02d}:{secend:02d} ",30,32)
oled.show()
oled.fill(0)
time.sleep(1)