import esp
esp.osdebug(None)
import gc
gc.collect()
import ntptime
import network
import tm1637
import time
import ds1307
import machine
from machine import Pin, RTC
rtc = RTC()
tm = tm1637.TM1637(clk=Pin(5), dio=Pin(4))
delay_ms = 100
# Initialize I2C and DS1307 RTC
i2c = machine.SoftI2C(scl=machine.Pin(22), sda=machine.Pin(21))
ds = ds1307.DS1307(i2c)
ds.halt(False)
print("Connecting to WiFi", end="")
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('Wokwi-GUEST', '')
while not sta_if.isconnected():
time.sleep_ms(1000)
print(".", end="")
print("Connected!")
time.sleep_ms(200)
time_offset=0
ntptime.host = "time.apple.com"
ntptime.settime()
now = rtc.datetime()
rtcnow = (now[0], now[1], now[2], now[3], now[4]+time_offset, now[5], now[6], now[7])
rtc.init(rtcnow)
ds.datetime(rtcnow)
time.sleep(1)
print("")
while True:
beats = 10*round((round((time.time()+3600) % 86400) / 86.4),1)
beats = int(beats)
hundreds = int(beats/100)
tens = int(beats) % 100
print(beats)
tm.numbers(hundreds,tens,False)
time.sleep_ms(500)
tm.numbers(hundreds,tens,False)
time.sleep_ms(500)