from machine import Pin, I2C
from time import sleep
from pico_i2c_lcd import I2cLcd
import urtc
# I2C do display LCD
# LCD SDA -> GP16
# LCD SCL -> GP17
i2c_lcd = I2C(0, sda=Pin(16), scl=Pin(17), freq=100000)
# I2C do RTC
# RTC SDA -> GP18
# RTC SCL -> GP19
i2c_rtc = I2C(1, sda=Pin(18), scl=Pin(19), freq=100000)
# Display LCD 16x2 com módulo I2C
lcd = I2cLcd(i2c_lcd, 0x27, 2, 16)
# RTC usado no Wokwi
rtc = urtc.DS1307(i2c_rtc)
# No projeto físico com DS3231, trocar por:
# rtc = urtc.DS3231(i2c_rtc)
while True:
data_hora = rtc.datetime()
lcd.clear()
lcd.move_to(0, 0)
lcd.putstr(f"{data_hora.day:02d}/{data_hora.month:02d}/{data_hora.year}")
lcd.move_to(0, 1)
lcd.putstr(f"{data_hora.hour:02d}:{data_hora.minute:02d}:{data_hora.second:02d}")
sleep(1)