from machine import I2C, Pin, RTC
from time import sleep
from i2c_lcd import I2cLcd
from machine import SoftI2C
from lcd_api import LcdApi
import ds1307
# Initialize the I2C for RTC
i2c_rtc = SoftI2C(scl=Pin(22), sda=Pin(21))
rtc = ds1307.DS1307(i2c_rtc)
# Initialize the I2C for LCD
i2c_lcd = SoftI2C(scl=Pin(3), sda=Pin(2), freq=400000)
lcd = I2cLcd(i2c_lcd, 0x27, 2, 16)
while True:
# Read the date and time from the RTC
datetime = rtc.datetime()
(Y, M, D, _, hr, m, s, _) = datetime
datetime_str = "{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}".format(Y, M, D, hr, m, s)
# Clear the LCD display and print the datetime
lcd.clear()
lcd.putstr(datetime_str)
print("Current date and time:", datetime_str)
sleep(1)