Skip to content

Commit 9b0d02c

Browse files
committed
First commit
1 parent be3fc76 commit 9b0d02c

File tree

1 file changed

+87
-0
lines changed
  • Matrix_Portal_M4_Boxing_Interval_Timer

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import time
2+
import displayio
3+
import terminalio
4+
from adafruit_display_text.label import Label
5+
from adafruit_bitmap_font import bitmap_font
6+
from adafruit_matrixportal.matrix import Matrix
7+
8+
# set the timer length
9+
TIMER_LENGTH = 180 # 3 minutes
10+
11+
BLINK = True
12+
DEBUG = False
13+
14+
# --- Display setup ---
15+
matrix = Matrix()
16+
display = matrix.display
17+
18+
# --- Drawing setup ---
19+
group = displayio.Group() # Create a Group
20+
bitmap = displayio.Bitmap(64, 32, 2) # Create a bitmap object,width, height, bit depth
21+
color = displayio.Palette(4) # Create a color palette
22+
color[0] = 0x000000 # black background
23+
color[1] = 0xFF0000 # red
24+
color[2] = 0xFF8C00 # yellow
25+
color[3] = 0x3DEB34 # green
26+
27+
# Create a TileGrid using the Bitmap and Palette
28+
tile_grid = displayio.TileGrid(bitmap, pixel_shader=color)
29+
group.append(tile_grid) # Add the TileGrid to the Group
30+
display.show(group)
31+
32+
if not DEBUG:
33+
font = bitmap_font.load_font("/IBMPlexMono-Medium-24_jep.bdf")
34+
else:
35+
font = terminalio.FONT
36+
37+
clock_label = Label(font)
38+
39+
def update_time(remaining_time):
40+
now = time.localtime() # Get the time values we need
41+
42+
# calculate remaining time in seconds
43+
seconds = remaining_time % 60
44+
minutes = remaining_time // 60
45+
46+
if BLINK:
47+
colon = ":" if now[5] % 2 else " "
48+
else:
49+
colon = ":"
50+
51+
clock_label.text = "{minutes:02d}{colon}{seconds:02d}".format(
52+
minutes=minutes, seconds=seconds, colon=colon
53+
)
54+
55+
if remaining_time < 60:
56+
clock_label.color = color[1]
57+
elif remaining_time < 90:
58+
clock_label.color = color[2]
59+
elif remaining_time > 90:
60+
clock_label.color = color[3]
61+
62+
bbx, bby, bbwidth, bbh = clock_label.bounding_box
63+
# Center the label
64+
clock_label.x = round(display.width / 2 - bbwidth / 2)
65+
clock_label.y = display.height // 2
66+
if DEBUG:
67+
print("Label bounding box: {},{},{},{}".format(bbx, bby, bbwidth, bbh))
68+
print("Label x: {} y: {}".format(clock_label.x, clock_label.y))
69+
70+
# decrement remaining time
71+
remaining_time -= 1
72+
if remaining_time < 0:
73+
remaining_time = TIMER_LENGTH
74+
75+
return remaining_time
76+
77+
def main():
78+
remaining_time = TIMER_LENGTH
79+
update_time(remaining_time)
80+
group.append(clock_label)
81+
82+
while True:
83+
remaining_time = update_time(remaining_time)
84+
time.sleep(1)
85+
86+
if __name__ == "__main__":
87+
main()

0 commit comments

Comments
 (0)