Skip to content

Commit 88cc64a

Browse files
committed
matrix bicolor ported, tested, linted
1 parent b734da7 commit 88cc64a

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

Matrix_7-Segment_LED_Backpack_Raspberry_Pi/matrix8x8_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# illuminate a column one LED at a time
2525
while col < col_max:
26-
matrix[row, col] = 1
26+
matrix[row, col] = 2
2727
col += 1
2828
time.sleep(.2)
2929

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Import all pins
2+
import time
3+
import board
4+
import busio
5+
from adafruit_ht16k33 import matrix
6+
7+
# Create the I2C interface
8+
i2c = busio.I2C(board.SCL, board.SDA)
9+
10+
# Create the LED bargraph class.
11+
bicolor = matrix.Matrix8x8x2(i2c)
12+
13+
# color mapping shortcut
14+
OFF = 0
15+
GREEN = 1
16+
RED = 2
17+
YELLOW = 3
18+
19+
# Set individual segments of the bicolor matrix
20+
# Illuminate the first three pixels
21+
bicolor[0,0] = GREEN
22+
bicolor[0,1] = RED
23+
bicolor[0,2] = YELLOW
24+
25+
time.sleep(2)
26+
27+
# Edges of an 8x8 matrix
28+
col_max = 8
29+
row_max = 8
30+
31+
# Turn all pixels off
32+
bicolor.fill(OFF)
33+
col = 0
34+
row = 0
35+
36+
# Illuminate each pixel with each color
37+
while row < row_max:
38+
39+
# Turn them on in a loop
40+
while col < col_max:
41+
bicolor[row, col] = RED
42+
time.sleep(.25)
43+
bicolor[row, col] = GREEN
44+
time.sleep(.25)
45+
bicolor[row, col] = YELLOW
46+
time.sleep(.25)
47+
col += 1
48+
49+
# next row when previous column is full
50+
if row < row_max:
51+
row += 1
52+
col = 0
53+
54+
# clear matrix, start over
55+
else:
56+
row = col = 0
57+
bicolor.fill(OFF)
58+
59+
time.sleep(1)
60+
61+
# Fill the entrire display, with each color
62+
bicolor.fill(GREEN)
63+
time.sleep(1)
64+
bicolor.fill(RED)
65+
time.sleep(1)
66+
bicolor.fill(YELLOW)
67+
time.sleep(1)
68+
bicolor.fill(OFF)

0 commit comments

Comments
 (0)