Code: Select all
while True: # loop
switch.update() # all'inizio di ogni loop controlla il pulsante
timer = time.monotonic() - start_time // LINE 1
time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + interval)
# NUOVO
alarm.light_sleep_until_alarms(time_alarm) # NUOVO // LINE 2
# definisce timer come il tempo trascorso in ogni loop
if timer >= interval and timer <= (interval + buzz): // LINE 3
Looking at it more, you are unconditionally sleeping for interval seconds each time through the loop. That's probably not what you want. You probably want that only when timer < interval.
Dave