import machine
import ds1307
import time
# Initialize I2C and DS1307
i2c = machine.SoftI2C(scl=machine.Pin(22), sda=machine.Pin(21))
ds = ds1307.DS1307(i2c)
ds.halt(False)
# Set initial datetime (year, month, day, weekday (can be 0 and will be calculated), hour, minute, second, subsecond)
#now = (2024, 2, 5, 0, 14, 15, 16, 0)
# Set EXTERNAL RTC to the now-Variable
#ds.datetime(now)
# Set EXTERNAL RTC to the local Time of client
ds.datetime()
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:
# Object: Time of EXTERNEN RTC
print(ds.datetime())
# Fomarted Time
current_datetime = ds.datetime()
formatted_datetime = format_datetime(current_datetime)
print(formatted_datetime)
time.sleep(1)