Skip to content

Commit 1bcc136

Browse files
authored
Merge pull request #826 from adafruit/matrix-7-segment-led-backpack-merge
Matrix 7 segment led backpack merge
2 parents 8a81ff1 + a610a2a commit 1bcc136

4 files changed

Lines changed: 163 additions & 1 deletion

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import time
2+
import board
3+
import busio
4+
from adafruit_ht16k33 import segments
5+
6+
# Create the I2C interface.
7+
i2c = busio.I2C(board.SCL, board.SDA)
8+
9+
# Create the LED segment class.
10+
# This creates a 14 segment 4 character display:
11+
display = segments.Seg14x4(i2c)
12+
13+
# Clear the display.
14+
display.fill(0)
15+
16+
# set brightness, range 1-15, 15 max brightness
17+
display.brightness = 15
18+
19+
# show phrase on alphanumeric display
20+
message = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
21+
count = 0
22+
23+
# print one character at time with short sleep
24+
# creates smooth scrolling effect
25+
while count < len(message):
26+
display.print(message[count])
27+
count += 1
28+
time.sleep(0.3)
29+
30+
# Can just print a number
31+
display.print(42)
32+
time.sleep(1)
33+
34+
# Set the first character to '1':
35+
display[0] = '1'
36+
# Set the second character to '2':
37+
display[1] = '2'
38+
# Set the third character to 'A':
39+
display[2] = 'A'
40+
# Set the forth character to 'B':
41+
display[3] = 'B'
42+
time.sleep(1)
43+
44+
numbers = [0.0, 1.0, -1.0, 0.55, -0.55, 10.23, -10.2, 100.5, -100.5]
45+
46+
# print negative and positive floating point numbers
47+
for i in numbers:
48+
display.print(i)
49+
time.sleep(0.5)
50+
51+
# print hex values, enable colon
52+
for i in range(0xFF):
53+
display.fill(0)
54+
display.print(':')
55+
display.print(hex(i))
56+
time.sleep(0.25)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Basic example of using the Bi-color 24 segment bargraph display.
2+
# This example and library is meant to work with Adafruit CircuitPython API.
3+
# Author: Carter Nelson
4+
# License: Public Domain
5+
6+
import time
7+
import board
8+
import busio
9+
10+
# Import the Bicolor24 driver from the HT16K33 module
11+
from adafruit_ht16k33.bargraph import Bicolor24
12+
13+
# Create the I2C interface
14+
i2c = busio.I2C(board.SCL, board.SDA)
15+
16+
# Create the LED bargraph class.
17+
bc24 = Bicolor24(i2c)
18+
19+
# Set individual segments of bargraph
20+
bc24[0] = bc24.LED_RED
21+
bc24[1] = bc24.LED_GREEN
22+
bc24[2] = bc24.LED_YELLOW
23+
24+
time.sleep(2)
25+
26+
# Turn them all off
27+
bc24.fill(bc24.LED_OFF)
28+
29+
# Turn them on in a loop
30+
for i in range(24):
31+
bc24[i] = bc24.LED_RED
32+
time.sleep(0.1)
33+
bc24[i] = bc24.LED_OFF
34+
35+
time.sleep(1)
36+
37+
# Fill the entrire bargraph
38+
bc24.fill(bc24.LED_GREEN)

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)