Skip to content

Commit d91cc96

Browse files
committed
Add starter MatrixPortal example
1 parent eb16c1a commit d91cc96

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

examples/progressbar_matrixportal.py

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
# Source: https://github.com/ajs256/matrixportal-weather-display
5+
6+
# ############## IMPORTS ###############
7+
8+
# HARDWARE
9+
import time
10+
import board
11+
12+
# DISPLAY
13+
import displayio # Main display library
14+
import framebufferio # For showing things on the display
15+
import rgbmatrix # For talking to matrices specifically
16+
17+
# CONTROLS
18+
19+
from adafruit_progressbar.progressbar import ProgressBar
20+
21+
# ############## DISPLAY SETUP ###############
22+
23+
# If there was a display before (protomatter, LCD, or E-paper), release it so
24+
# we can create ours
25+
displayio.release_displays()
26+
27+
print("Setting up RGB matrix")
28+
29+
# This next call creates the RGB Matrix object itself. It has the given width
30+
# and height.
31+
#
32+
# These lines are for the Matrix Portal. If you're using a different board,
33+
# check the guide to find the pins and wiring diagrams for your board.
34+
# If you have a matrix with a different width or height, change that too.
35+
matrix = rgbmatrix.RGBMatrix(
36+
width=64,
37+
height=32,
38+
bit_depth=3,
39+
rgb_pins=[
40+
board.MTX_R1,
41+
board.MTX_G1,
42+
board.MTX_B1,
43+
board.MTX_R2,
44+
board.MTX_G2,
45+
board.MTX_B2,
46+
],
47+
addr_pins=[board.MTX_ADDRA, board.MTX_ADDRB, board.MTX_ADDRC, board.MTX_ADDRD],
48+
clock_pin=board.MTX_CLK,
49+
latch_pin=board.MTX_LAT,
50+
output_enable_pin=board.MTX_OE,
51+
)
52+
53+
# Associate the RGB matrix with a Display so that we can use displayio features
54+
display = framebufferio.FramebufferDisplay(matrix)
55+
56+
print("Adding display group")
57+
group = displayio.Group(max_size=5) # Create a group to hold all our labels
58+
display.show(group)
59+
60+
print("Creating progress bar and adding to group")
61+
progress_bar = ProgressBar(2, 8, 40, 14, 0.6)
62+
63+
group.insert(0, progress_bar)
64+
65+
progress_bar_value = 0.0
66+
progress_bar_incr = 3.0
67+
68+
while True:
69+
if progress_bar_value > 100:
70+
progress_bar_value = 100
71+
progress_bar_incr *= -1
72+
73+
if progress_bar_value < 0:
74+
progress_bar_value = 0
75+
progress_bar_incr *= -1
76+
77+
progress_bar.progress = progress_bar_value / 100
78+
progress_bar_value += progress_bar_incr
79+
time.sleep(0.5)

0 commit comments

Comments
 (0)