|
9 | 9 | import adafruit_pcf8523
|
10 | 10 | from simpleio import tone
|
11 | 11 | import neopixel
|
| 12 | +from adafruit_led_animation.animation.rainbow import Rainbow |
12 | 13 |
|
13 | 14 | rtc = adafruit_pcf8523.PCF8523(board.I2C())
|
14 | 15 | battery = LC709203F(board.I2C())
|
15 | 16 | indicator = neopixel.NeoPixel(board.A1, 1)
|
16 | 17 |
|
| 18 | +LEDs = neopixel.NeoPixel(board.A2, 20) |
| 19 | +LEDs.fill((0, 0, 0)) |
| 20 | +rainbow = Rainbow(LEDs, speed=0.1, period=2) |
| 21 | + |
17 | 22 | days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
|
18 | 23 | sleep = {
|
19 | 24 | 0: (22, 50),
|
20 |
| - 1: (22, 50), |
| 25 | + 1: (23, 8), |
21 | 26 | 2: (22, 50),
|
22 | 27 | 3: (22, 50),
|
23 | 28 | 4: (22, 50),
|
|
52 | 57 | (220, 2),
|
53 | 58 | ]
|
54 | 59 |
|
55 |
| -SET_DATE = True |
| 60 | +SET_DATE = False # Set this to True on first run and False for subsequent runs |
56 | 61 | if SET_DATE:
|
57 | 62 | # Make sure to set this to the current date and time before using
|
58 | 63 | YEAR = 2022
|
59 | 64 | MONTH = 3
|
60 |
| - DAY = 10 |
61 |
| - HOUR = 22 |
62 |
| - MINUTE = 49 |
63 |
| - SEC = 55 |
64 |
| - WDAY = 0 # 0 Sunday, 1 Monday, etc. |
| 65 | + DAY = 21 |
| 66 | + HOUR = 16 |
| 67 | + MINUTE = 54 |
| 68 | + SEC = 0 |
| 69 | + WDAY = 1 # 0 Sunday, 1 Monday, etc. |
65 | 70 | t = time.struct_time((YEAR, MONTH, DAY, HOUR, MINUTE, SEC, WDAY, -1, -1))
|
66 | 71 |
|
67 | 72 | print("Setting time to:", t) # uncomment for debugging
|
68 | 73 | rtc.datetime = t
|
69 | 74 | print()
|
70 | 75 |
|
| 76 | +on_always = True # Set to False for animation only to be on when alarm rings |
| 77 | + |
| 78 | +indicate = True |
| 79 | + |
| 80 | +start = time.monotonic() |
| 81 | +wait = 1 |
| 82 | + |
71 | 83 | while True:
|
72 |
| - t = rtc.datetime |
73 |
| - bat = min(max(int(battery.cell_percent), 0), 100) |
74 |
| - |
75 |
| - g = int((bat / 100) * 255) |
76 |
| - r = int((1 - (bat / 100)) * 255) |
77 |
| - indicator.fill([r, g, 0]) |
78 |
| - |
79 |
| - print(f"The date is {days[t.tm_wday]} {t.tm_mday}/{t.tm_mon}/{t.tm_year}") |
80 |
| - print(f"The time is {t.tm_hour}:{t.tm_min}:{t.tm_sec}") |
81 |
| - print(f"Battery: {bat}%") |
82 |
| - |
83 |
| - night = sleep[t.tm_wday] |
84 |
| - morning = wake[t.tm_wday] |
85 |
| - |
86 |
| - if night: |
87 |
| - if night[0] == t.tm_hour and night[1] == t.tm_min: |
88 |
| - for i in ringtone: |
89 |
| - print(i[0]) |
90 |
| - tone(board.A0, i[0], i[1] * (60 / BPM)) |
91 |
| - time.sleep(60) |
92 |
| - |
93 |
| - if morning: |
94 |
| - if morning[0] == t.tm_hour and morning[1] == t.tm_min: |
95 |
| - for i in ringtone: |
96 |
| - print(i[0]) |
97 |
| - tone(board.A0, i[0], i[1] * (60 / BPM)) |
98 |
| - time.sleep(60) |
99 |
| - |
100 |
| - time.sleep(1) |
| 84 | + if on_always: |
| 85 | + rainbow.animate() |
| 86 | + if time.monotonic() - start > wait: |
| 87 | + start = time.monotonic() |
| 88 | + wait = 1 |
| 89 | + t = rtc.datetime |
| 90 | + bat = min(max(int(battery.cell_percent), 0), 100) |
| 91 | + |
| 92 | + g = int((bat / 100) * 255) |
| 93 | + r = int((1 - (bat / 100)) * 255) |
| 94 | + if bat >= 15: |
| 95 | + indicator.fill([r, g, 0]) |
| 96 | + |
| 97 | + if bat < 15: |
| 98 | + if indicate: |
| 99 | + indicator.fill([0, 0, 0]) |
| 100 | + indicate = False |
| 101 | + else: |
| 102 | + indicator.fill([r, g, 0]) |
| 103 | + indicate = True |
| 104 | + |
| 105 | + print(f"Date: {days[t.tm_wday]} {t.tm_mday}/{t.tm_mon}/{t.tm_year}") |
| 106 | + print(f"Time: {t.tm_hour}:{t.tm_min}:{t.tm_sec}") |
| 107 | + print(f"Batt: {bat}%\n") |
| 108 | + |
| 109 | + night = sleep[t.tm_wday] |
| 110 | + morning = wake[t.tm_wday] |
| 111 | + |
| 112 | + if night: |
| 113 | + if night[0] == t.tm_hour and night[1] == t.tm_min: |
| 114 | + for i in ringtone: |
| 115 | + print(i[0]) |
| 116 | + tone(board.A0, i[0], i[1] * (60 / BPM)) |
| 117 | + wait = 60 |
| 118 | + if not on_always: |
| 119 | + while time.monotonic() - start < 5: |
| 120 | + rainbow.animate() |
| 121 | + rainbow.fill([0, 0, 0]) |
| 122 | + |
| 123 | + if morning: |
| 124 | + if morning[0] == t.tm_hour and morning[1] == t.tm_min: |
| 125 | + for i in ringtone: |
| 126 | + print(i[0]) |
| 127 | + tone(board.A0, i[0], i[1] * (60 / BPM)) |
| 128 | + wait = 60 |
| 129 | + if not on_always: |
| 130 | + while time.monotonic() - start < 5: |
| 131 | + rainbow.animate() |
| 132 | + rainbow.fill([0, 0, 0]) |
0 commit comments