Skip to content

adding text example. #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions examples/ht16k33_matrix_text_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Basic example of using FrameBuffer to create and scroll text on the matrix.

# Requires: adafruit_framebuf

import board
import busio
import adafruit_framebuf

# Import the HT16K33 LED matrix module.
from adafruit_ht16k33 import matrix

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

# Create the matrix class.
# This creates a 16x8 matrix:
matrix = matrix.Matrix16x8(i2c)

# Low brightness so it's easier to look at
matrix.brightness = 0

# Clear the matrix.
matrix.fill(0)

text_to_show = "Hello Blinka"

# Create a framebuffer for our display
buf = bytearray(16) # 1 bytes tall x 16 wide = 16 bytes
fb = adafruit_framebuf.FrameBuffer(buf, 16, 8, adafruit_framebuf.MVLSB)


while True:
for i in range(len(text_to_show) * 8):
fb.fill(0)
fb.text(text_to_show, -i + 16, 0, color=1)
# turn all LEDs off
matrix.fill(0)
for x in range(16):
# using the FrameBuffer text result
bite = buf[x]
for y in range(8):
bit = 1 << y & bite
# if bit > 0 then set the pixel brightness
if bit:
matrix[16-x, y+1] = 1