Skip to content

Commit 35a7bd7

Browse files
committed
Add starter MatrixPortal example
1 parent eb16c1a commit 35a7bd7

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

examples/progressbar_matrixportal.py

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
# BASICS (these are all built in)
9+
import time # The function to use the onboard RTC to give us time values
10+
import board # Pin definitions
11+
import terminalio # Provides the font we use
12+
import busio # Provides SPI for talking to the ESP32
13+
import digitalio # Provides pin I/O for the ESP32
14+
import rtc # Lets us keep track of the time
15+
import neopixel # To drive the onboard NeoPixel.
16+
17+
# INTERNET
18+
import adafruit_requests as requests # For getting data from the Internet
19+
from adafruit_esp32spi import adafruit_esp32spi # For talking to the ESP32
20+
import adafruit_esp32spi.adafruit_esp32spi_socket as socket # For using the ESP32 for internet connections
21+
from adafruit_io.adafruit_io import IO_HTTP # For talking to Adafruit IO
22+
from config import config # The config file, see the README for what to put here
23+
from secrets import secrets # secrets, etc.
24+
25+
# DISPLAY
26+
from adafruit_display_text import label # For showing text on the display
27+
import displayio # Main display library
28+
import framebufferio # For showing things on the display
29+
import rgbmatrix # For talking to matrices specifically
30+
from adafruit_bitmap_font import bitmap_font # Fonty goodness
31+
32+
# CONTROLS
33+
34+
# from adafruit_verticalprogressbar import ProgressBar
35+
from adafruit_progressbar import ProgressBar
36+
37+
# ############## DISPLAY SETUP ###############
38+
39+
# If there was a display before (protomatter, LCD, or E-paper), release it so
40+
# we can create ours
41+
displayio.release_displays()
42+
43+
print("Setting up RGB matrix")
44+
45+
# This next call creates the RGB Matrix object itself. It has the given width
46+
# and height.
47+
#
48+
# These lines are for the Matrix Portal. If you're using a different board,
49+
# check the guide to find the pins and wiring diagrams for your board.
50+
# If you have a matrix with a different width or height, change that too.
51+
matrix = rgbmatrix.RGBMatrix(
52+
width=64,
53+
height=32,
54+
bit_depth=3,
55+
rgb_pins=[
56+
board.MTX_R1,
57+
board.MTX_G1,
58+
board.MTX_B1,
59+
board.MTX_R2,
60+
board.MTX_G2,
61+
board.MTX_B2,
62+
],
63+
addr_pins=[board.MTX_ADDRA, board.MTX_ADDRB, board.MTX_ADDRC, board.MTX_ADDRD],
64+
clock_pin=board.MTX_CLK,
65+
latch_pin=board.MTX_LAT,
66+
output_enable_pin=board.MTX_OE,
67+
)
68+
69+
font_list = ["helvR10", "helvB12", "IBMPlexMono-Medium-24_jep", "6x10", "cozette"]
70+
71+
# Associate the RGB matrix with a Display so that we can use displayio features
72+
display = framebufferio.FramebufferDisplay(matrix)
73+
74+
print("Adding display group")
75+
76+
group = displayio.Group(max_size=5) # Create a group to hold all our labels
77+
78+
display.show(group)
79+
80+
print("Creating progress bar and adding to group")
81+
# progress_bar = ProgressBar((2, 4), (20, 20), margin=False)
82+
83+
progress_bar = ProgressBar(2, 8, 40, 14, 0.6)
84+
85+
# progress_bar.progress = 0.0
86+
# progress_bar.flip_x = True
87+
# progress_bar.flip_y = True
88+
# progress_bar.transpose_xy = True
89+
90+
group.insert(0, progress_bar)
91+
92+
progress_bar_value = 0.0
93+
progress_bar_incr = 3.0
94+
95+
while True:
96+
if progress_bar_value > 100:
97+
progress_bar_value = 100
98+
progress_bar_incr *= -1
99+
100+
if progress_bar_value < 0:
101+
progress_bar_value = 0
102+
progress_bar_incr *= -1
103+
104+
progress_bar.progress = progress_bar_value / 100
105+
progress_bar_value += progress_bar_incr
106+
time.sleep(0.5)

0 commit comments

Comments
 (0)