Skip to content

Commit 3907b18

Browse files
committed
adding text example.
1 parent ae7101a commit 3907b18

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Basic example of using FrameBuffer to create and scroll text on the matrix.
2+
3+
# Requires: adafruit_framebuf
4+
5+
import time
6+
import board
7+
import busio
8+
import adafruit_framebuf
9+
10+
# Import the HT16K33 LED matrix module.
11+
from adafruit_ht16k33 import matrix
12+
13+
# Create the I2C interface.
14+
i2c = busio.I2C(board.SCL, board.SDA)
15+
16+
# Create the matrix class.
17+
# This creates a 16x8 matrix:
18+
matrix = matrix.Matrix16x8(i2c)
19+
20+
# Low brightness so it's easier to look at
21+
matrix.brightness = 0
22+
23+
# Clear the matrix.
24+
matrix.fill(0)
25+
26+
text_to_show = "Hello Blinka"
27+
28+
# Create a framebuffer for our display
29+
buf = bytearray(16) # 1 bytes tall x 16 wide = 16 bytes
30+
fb = adafruit_framebuf.FrameBuffer(buf, 16, 8, adafruit_framebuf.MVLSB)
31+
32+
33+
while True:
34+
for i in range(len(text_to_show) * 8):
35+
fb.fill(0)
36+
fb.text(text_to_show, -i + 16, 0, color=1)
37+
# turn all LEDs off
38+
matrix.fill(0)
39+
for x in range(16):
40+
# using the FrameBuffer text result
41+
bite = buf[x]
42+
for y in range(8):
43+
bit = 1 << y & bite
44+
# if bit > 0 then set the pixel brightness
45+
if bit:
46+
matrix[16-x, y+1] = 1

0 commit comments

Comments
 (0)