# Generic imports
import ntptime
import network
import time
# Hardware classes
from hw import *
# Libraries
from anim import *
import color
def get_time():
t = time.localtime()
return t[3]+2, t[4], t[5]
def get_time_hand():
h, m, s = get_time()
# Get position of hand for current time (0 to 1)
total_minutes = (h % 12) * 3600 + m * 60 + s
return (total_minutes / (12 * 60 * 60))
# Define Hardware
segdis = SegDis(clk=machine.Pin(18), dio=machine.Pin(19))
ledring = Wheel(color.Color(50, 100, 150), 36, 17)
led_left, led_right = LED(machine.Pin(26)), LED(machine.Pin(22))
# Startup procedure
segdis.hw.show('----')
led_left.set_brightness(0)
led_right.set_brightness(1)
print("Establishing WiFi connection...", end=" ")
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('Wokwi-GUEST', '')
print("success")
print("Getting current time...", end=" ")
# Set loading animation (Does this actually work??)
manager = AnimationManager(ledring)
fade = FadeAnimation("startup", ledring, duration_ms=2000, loops=1)
manager.start(fade)
while True:
if not manager.active_anim:
manager.start(fade)
manager.next_frame()
try:
ntptime.settime()
except:
time.sleep(0.05)
continue
h, m, s= get_time()
segdis.hw.numbers(h, m)
print(f"{h}:{m}")
break
# Confirm successfull startup
print("Startup completed!")
#manager = AnimationManager(ledring)
#fade = SparkleAnimation("fade", ledring, duration_ms=2000, loops=2)
#manager.start(fade)
ledring.show_clock(h, m, 1)
test = LoadingRingAnimation(
name = "test",
hw = ledring,
dur_ms=1000,
loops=1,
ini_spread=1,
max_spread=3,
)
manager.start(test)
while True:
# To each full minute, update the display and execute a rot animation
h, m, s = get_time()
if s == 0 and not manager.active_anim:
segdis.hw.numbers(h, m)
new_minute_rot = LoadingRingAnimation(
name = "load",
hw = ledring,
dur_ms=2000,
loops=1,
ini_spread=1,
max_spread=3,
ini_angle=get_time_hand())
manager.start(new_minute_rot)
if not manager.active_anim:
ledring.show_clock(h, m, 1)
# Update wheel if active animation
if manager.active_anim:
manager.next_frame()
else:
pass # Wait for next minute here
# Refresh time during the night
if h == 2 and m == 0:
ntptime.settime()
time.sleep(0.05)