Skip to content

Commit 94464e6

Browse files
authored
Merge pull request #2118 from evaherrada/blahaj-fix
Updated blahaj code
2 parents d642a9c + 019dc52 commit 94464e6

File tree

1 file changed

+68
-36
lines changed

1 file changed

+68
-36
lines changed

blahaj/code.py

Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99
import adafruit_pcf8523
1010
from simpleio import tone
1111
import neopixel
12+
from adafruit_led_animation.animation.rainbow import Rainbow
1213

1314
rtc = adafruit_pcf8523.PCF8523(board.I2C())
1415
battery = LC709203F(board.I2C())
1516
indicator = neopixel.NeoPixel(board.A1, 1)
1617

18+
LEDs = neopixel.NeoPixel(board.A2, 20)
19+
LEDs.fill((0, 0, 0))
20+
rainbow = Rainbow(LEDs, speed=0.1, period=2)
21+
1722
days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
1823
sleep = {
1924
0: (22, 50),
20-
1: (22, 50),
25+
1: (23, 8),
2126
2: (22, 50),
2227
3: (22, 50),
2328
4: (22, 50),
@@ -52,49 +57,76 @@
5257
(220, 2),
5358
]
5459

55-
SET_DATE = True
60+
SET_DATE = False # Set this to True on first run and False for subsequent runs
5661
if SET_DATE:
5762
# Make sure to set this to the current date and time before using
5863
YEAR = 2022
5964
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.
6570
t = time.struct_time((YEAR, MONTH, DAY, HOUR, MINUTE, SEC, WDAY, -1, -1))
6671

6772
print("Setting time to:", t) # uncomment for debugging
6873
rtc.datetime = t
6974
print()
7075

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+
7183
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

Comments
 (0)