import machine
import ds1307
import time
# Initialize I2C and DS1307
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
ds = ds1307.DS1307(i2c)
ds.halt(False)
# Set initial datetime (year, month, day, weekday, hour, minute, second, subsecond)
now = (2023, 10, 27, 1, 5, 16, 3, 0, 0)
def format_datetime(datetime):
year, month, day, weekday, hour, minute, second, subsecond = datetime
return f"{year}-{month:02d}-{day:02d} {hour:02d}:{minute:02d}:{second:02d}"
while True:
current_datetime = ds.datetime()
formatted_datetime = format_datetime(current_datetime)
print(formatted_datetime)
time.sleep(1)