from machine import I2C, Pin
from ds1307 import DS1307
from lcd_i2c import LCD
from time import sleep
# I2C do LCD: GP0 (SDA), GP1 (SCL)
i2c_lcd = I2C(0, scl=Pin(1), sda=Pin(0))
# I2C do DS1307: GP2 (SDA), GP3 (SCL)
i2c_rtc = I2C(1, scl=Pin(3), sda=Pin(2))
# Inicializa display e RTC
display = LCD(0x27, 16, 2, i2c=i2c_lcd)
rtc = DS1307(i2c_rtc)
# Inicia o display
display.begin()
display.clear()
def Relogio():
tempo = rtc.datetime()
display.set_cursor(0, 0)
display.print("Data: {:02d}/{:02d}/{}".format(tempo[2], tempo[1], tempo[0]))
display.set_cursor(0, 1)
display.print("Hora: {:02d}:{:02d}:{:02d}".format(tempo[4], tempo[5], tempo[6]))
sleep(1)
while True:
Relogio()