Skip to content

Commit 7336977

Browse files
committed
first commit
1 parent 20af800 commit 7336977

File tree

8 files changed

+24986
-0
lines changed

8 files changed

+24986
-0
lines changed
4.05 KB
Binary file not shown.
4.05 KB
Binary file not shown.
4.05 KB
Binary file not shown.
Binary file not shown.
4.05 KB
Binary file not shown.
4.05 KB
Binary file not shown.

Halloween_Countdown_Matrix/fonts/Arial-12.bdf

+24,874
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import time
2+
import board
3+
from adafruit_matrixportal.matrixportal import MatrixPortal
4+
5+
EVENT_YEAR = 2020
6+
EVENT_MONTH = 10
7+
EVENT_DAY = 31
8+
EVENT_HOUR = 17
9+
EVENT_MINUTE = 0
10+
11+
FRAME_DURATION = 3
12+
FRAMES = (
13+
"bmps/jack.bmp",
14+
"DAYS",
15+
"bmps/ghost.bmp",
16+
"HOURS",
17+
"bmps/bats.bmp",
18+
"MINUTES",
19+
"bmps/skull.bmp",
20+
"bmps/halloween.bmp",
21+
)
22+
23+
EVENT_DAY_IMAGE = "bmps/happy_halloween.bmp"
24+
SYNCHRONIZE_CLOCK = True
25+
26+
# --- Display setup ---
27+
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=True)
28+
29+
current_frame = None
30+
31+
# Create a new label with the color and text selected
32+
matrixportal.add_text(
33+
text_font="fonts/Arial-12.bdf",
34+
text_position=(4, (matrixportal.graphics.display.height // 2) - 1),
35+
text_color=0xEF7F31,
36+
)
37+
38+
39+
def set_time_until(unit=None):
40+
event_time = time.struct_time(
41+
(
42+
EVENT_YEAR,
43+
EVENT_MONTH,
44+
EVENT_DAY,
45+
EVENT_HOUR,
46+
EVENT_MINUTE,
47+
0, # we don't track seconds
48+
-1,
49+
-1,
50+
False,
51+
)
52+
)
53+
remaining = time.mktime(event_time) - time.mktime(time.localtime())
54+
if remaining <= 0:
55+
# oh, its event time!
56+
matrixportal.set_background(EVENT_DAY_IMAGE)
57+
return
58+
remaining //= 60
59+
mins_remaining = remaining % 60
60+
remaining //= 60
61+
hours_remaining = remaining % 24
62+
remaining //= 24
63+
days_remaining = remaining
64+
65+
if unit == "DAYS":
66+
text = "{} day".format(days_remaining)
67+
if days_remaining != 1:
68+
text += "s"
69+
if unit == "HOURS":
70+
text = "{} hour".format(hours_remaining)
71+
if hours_remaining != 1:
72+
text += "s"
73+
if unit == "MINUTES":
74+
text = "{} min".format(mins_remaining)
75+
if mins_remaining != 1:
76+
text += "s"
77+
matrixportal.set_text(text)
78+
matrixportal.set_background(0)
79+
80+
81+
def set_next_frame():
82+
# pylint: disable=global-statement
83+
global current_frame
84+
85+
# Advance to next frame if we already have one
86+
if current_frame is not None:
87+
current_frame += 1
88+
89+
# Loop back or set initial frame
90+
if current_frame is None or current_frame >= len(FRAMES):
91+
current_frame = 0
92+
93+
# Check if Picture or Text
94+
print(FRAMES[current_frame])
95+
if FRAMES[current_frame][-4:] == ".bmp":
96+
matrixportal.set_background(FRAMES[current_frame])
97+
matrixportal.set_text("")
98+
else:
99+
set_time_until(FRAMES[current_frame])
100+
101+
102+
# Simulate the delay in case fetching time is fast
103+
set_next_frame()
104+
start_time = time.monotonic()
105+
if SYNCHRONIZE_CLOCK:
106+
matrixportal.get_local_time()
107+
while time.monotonic() < start_time + FRAME_DURATION:
108+
pass
109+
110+
while True:
111+
set_next_frame()
112+
time.sleep(FRAME_DURATION)

0 commit comments

Comments
 (0)