Skip to content

Commit 7f39c47

Browse files
authored
Merge pull request #799 from adafruit/Matrix_7-Segment_LED_Backpack_Raspberry_Pi
Matrix 7 segment led backpack raspberry pi
2 parents 0a7c087 + a5329a0 commit 7f39c47

5 files changed

Lines changed: 118 additions & 0 deletions

File tree

Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Matrix_7-Segment_LED_Backpack_Raspberry_Pi
2+
3+
Code to accompany this tutorial:
4+
https://learn.adafruit.com/matrix-7-segment-led-backpack-with-the-raspberry-pi/
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Import all board 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+
# creates a 8x8 matrix:
11+
matrix = matrix.Matrix8x8(i2c)
12+
13+
# edges of an 8x8 matrix
14+
col_max = 8
15+
row_max = 8
16+
17+
# Clear the matrix.
18+
matrix.fill(0)
19+
col = 0
20+
row = 0
21+
22+
while True:
23+
24+
# illuminate a column one LED at a time
25+
while col < col_max:
26+
matrix[row, col] = 1
27+
col += 1
28+
time.sleep(.2)
29+
30+
# next row when previous column is full
31+
if row < row_max:
32+
row += 1
33+
col = 0
34+
35+
# clear matrix, start over
36+
else:
37+
row = col = 0
38+
matrix.fill(0)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import time
2+
import datetime
3+
from adafruit_ht16k33 import segments
4+
import board
5+
import busio
6+
7+
# Create the I2C interface.
8+
i2c = busio.I2C(board.SCL, board.SDA)
9+
10+
# Create the LED segment class.
11+
# This creates a 7 segment 4 character display:
12+
display = segments.Seg7x4(i2c)
13+
14+
# clear display
15+
display.fill(0)
16+
17+
while True:
18+
# get system time
19+
now = datetime.datetime.now()
20+
hour = now.hour
21+
minute = now.minute
22+
second = now.second
23+
24+
# setup HH:MM for display and print it
25+
clock = '%02d%02d' % (hour,minute) # concat hour + minute, add leading zeros
26+
display.print(clock)
27+
28+
# Toggle colon when displaying time
29+
if second % 2:
30+
display.print(':') # Enable colon every other second
31+
else:
32+
display.print(';') # Turn off colon
33+
34+
time.sleep(0.5)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 7 segment 4 character display:
11+
display = segments.Seg7x4(i2c)
12+
13+
# Clear the display.
14+
display.fill(0)
15+
16+
# Can just print a number
17+
display.print(42)
18+
time.sleep(1)
19+
20+
# Set the first character to '1':
21+
display[0] = '1'
22+
# Set the second character to '2':
23+
display[1] = '2'
24+
# Set the third character to 'A':
25+
display[2] = 'A'
26+
# Set the forth character to 'B':
27+
display[3] = 'B'
28+
time.sleep(1)
29+
30+
numbers = [0.0, 1.0, -1.0, 0.55, -0.55, 10.23, -10.2, 100.5, -100.5]
31+
32+
# print negative and positive floating point numbers
33+
for i in numbers:
34+
display.print(i)
35+
time.sleep(0.5)
36+
37+
# print hex values, enable colon
38+
for i in range(0xFF):
39+
display.fill(0)
40+
display.print(':')
41+
display.print(hex(i))
42+
time.sleep(0.25)

0 commit comments

Comments
 (0)