Skip to content

Commit 9dd680a

Browse files
committed
Added blahaj code
1 parent 3a278ba commit 9dd680a

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

blahaj/code.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# SPDX-FileCopyrightText: 2022 Eva Herrada for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
7+
import board
8+
import busio
9+
from adafruit_lc709203f import LC709203F
10+
import adafruit_pcf8523
11+
from simpleio import tone
12+
import neopixel
13+
14+
rtc = adafruit_pcf8523.PCF8523(board.I2C())
15+
battery = LC709203F(board.I2C())
16+
indicator = neopixel.NeoPixel(board.A1, 1)
17+
18+
days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
19+
sleep = {
20+
0: (22, 50),
21+
1: (22, 50),
22+
2: (22, 50),
23+
3: (22, 50),
24+
4: (22, 50),
25+
5: None,
26+
6: None,
27+
}
28+
wake = {
29+
0: (11, 30),
30+
1: (9, 50),
31+
2: (9, 50),
32+
3: (9, 50),
33+
4: (9, 50),
34+
5: (9, 50),
35+
6: (11, 30),
36+
}
37+
38+
BPM = 160
39+
40+
ringtone = [
41+
(330, 0.5),
42+
(294, 0.5),
43+
(185, 1),
44+
(208, 1),
45+
(277, 0.5),
46+
(247, 0.5),
47+
(147, 1),
48+
(165, 1),
49+
(247, 0.5),
50+
(220, 0.5),
51+
(139, 1),
52+
(165, 1),
53+
(220, 2),
54+
]
55+
56+
SET_DATE = True
57+
if SET_DATE:
58+
# Make sure to set this to the current date and time before using
59+
YEAR = 2022
60+
MONTH = 3
61+
DAY = 10
62+
HOUR = 22
63+
MINUTE = 49
64+
SEC = 55
65+
WDAY = 0 # 0 Sunday, 1 Monday, etc.
66+
t = time.struct_time((YEAR, MONTH, DAY, HOUR, MINUTE, SEC, WDAY, -1, -1))
67+
68+
print("Setting time to:", t) # uncomment for debugging
69+
rtc.datetime = t
70+
print()
71+
72+
while True:
73+
t = rtc.datetime
74+
bat = min(max(int(battery.cell_percent), 0), 100)
75+
76+
g = int((bat / 100) * 255)
77+
r = int((1 - (bat / 100)) * 255)
78+
indicator.fill([r, g, 0])
79+
80+
print(f"The date is {days[t.tm_wday]} {t.tm_mday}/{t.tm_mon}/{t.tm_year}")
81+
print(f"The time is {t.tm_hour}:{t.tm_min}:{t.tm_sec}")
82+
print(f"Battery: {bat}%")
83+
84+
night = sleep[t.tm_wday]
85+
morning = wake[t.tm_wday]
86+
87+
if night:
88+
if night[0] == t.tm_hour and night[1] == t.tm_min:
89+
for i in ringtone:
90+
print(i[0])
91+
tone(board.A0, i[0], i[1] * (60 / BPM))
92+
time.sleep(60)
93+
94+
if morning:
95+
if morning[0] == t.tm_hour and morning[1] == t.tm_min:
96+
for i in ringtone:
97+
print(i[0])
98+
tone(board.A0, i[0], i[1] * (60 / BPM))
99+
time.sleep(60)
100+
101+
time.sleep(1)

0 commit comments

Comments
 (0)