-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
57 lines (50 loc) · 1.59 KB
/
code.py
File metadata and controls
57 lines (50 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import board
import digitalio
import time
import alarm
BEEP_SHORT = 0.05
BEEP_LONG = 0.1
CYCLE_TIME = 10
buzzer = digitalio.DigitalInOut(board.GP0)
buzzer.direction = digitalio.Direction.OUTPUT
button_alarm = alarm.pin.PinAlarm(pin=board.GP1, value=False, pull=True)
if (
alarm.wake_alarm is None or isinstance(alarm.wake_alarm, alarm.time.TimeAlarm)
):
# Beep
buzzer.value = True
time.sleep(BEEP_LONG)
buzzer.value = False
time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + CYCLE_TIME)
alarm.exit_and_deep_sleep_until_alarms(time_alarm, button_alarm)
elif (
isinstance(alarm.wake_alarm, alarm.time.PinAlarm) and alarm.sleep_memory[0] == False
):
# "ON" chirp
buzzer.value = True
time.sleep(BEEP_SHORT)
buzzer.value = False
time.sleep(BEEP_SHORT)
buzzer.value = True
time.sleep(BEEP_SHORT)
buzzer.value = False
alarm.sleep_memory[0] = True
time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + CYCLE_TIME)
alarm.exit_and_deep_sleep_until_alarms(time_alarm, button_alarm)
elif (
isinstance(alarm.wake_alarm, alarm.time.PinAlarm) and alarm.sleep_memory[0] == True
):
# "OFF" chirp
buzzer.value = True
time.sleep(BEEP_SHORT)
buzzer.value = False
time.sleep(BEEP_SHORT)
buzzer.value = True
time.sleep(BEEP_SHORT)
buzzer.value = False
time.sleep(BEEP_SHORT)
buzzer.value = True
time.sleep(BEEP_SHORT)
buzzer.value = False
alarm.sleep_memory[0] = False
alarm.exit_and_deep_sleep_until_alarms(button_alarm)