# Piezo Buzzer Alarm Example
import alarm
import board
import simpleio
import time
# Time in seconds between updates (polling)
# 600 = 10 mins, 900 = 15 mins, 1800 = 30 mins, 3600 = 1 hour
sleep_time = 10
buzzer_pin = board.GP0 #other leg of buzzer goes to a GND pin
def time_calc(input_time):
if input_time < 60:
sleep_int = input_time
time_output = f"{sleep_int:.0f} seconds"
elif 60 <= input_time < 3600:
sleep_int = input_time / 60
time_output = f"{sleep_int:.0f} minutes"
elif 3600 <= input_time < 86400:
sleep_int = input_time / 60 / 60
time_output = f"{sleep_int:.0f} hours"
else:
sleep_int = input_time / 60 / 60 / 24
time_output = f"{sleep_int:.1f} days"
return time_output
while True:
print("Beep...")
simpleio.tone(buzzer_pin, 1000, duration=1)
print("Next Update: ", time_calc(sleep_time))
time.sleep(sleep_time)