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