/ examples / ht16k33_matrix_simpletest.py
ht16k33_matrix_simpletest.py
 1  # Basic example of clearing and drawing a pixel on a LED matrix display.
 2  # This example and library is meant to work with Adafruit CircuitPython API.
 3  # Author: Tony DiCola
 4  # License: Public Domain
 5  
 6  # Import all board pins.
 7  import time
 8  import board
 9  import busio
10  
11  # Import the HT16K33 LED matrix module.
12  from adafruit_ht16k33 import matrix
13  
14  
15  # Create the I2C interface.
16  i2c = busio.I2C(board.SCL, board.SDA)
17  
18  # Create the matrix class.
19  # This creates a 16x8 matrix:
20  matrix = matrix.Matrix16x8(i2c)
21  # Or this creates a 16x8 matrix backpack:
22  # matrix = matrix.MatrixBackpack16x8(i2c)
23  # Or this creates a 8x8 matrix:
24  # matrix = matrix.Matrix8x8(i2c)
25  # Or this creates a 8x8 bicolor matrix:
26  # matrix = matrix.Matrix8x8x2(i2c)
27  # Finally you can optionally specify a custom I2C address of the HT16k33 like:
28  # matrix = matrix.Matrix16x8(i2c, address=0x70)
29  
30  # Clear the matrix.
31  matrix.fill(0)
32  
33  # Set a pixel in the origin 0, 0 position.
34  matrix[0, 0] = 1
35  # Set a pixel in the middle 8, 4 position.
36  matrix[8, 4] = 1
37  # Set a pixel in the opposite 15, 7 position.
38  matrix[15, 7] = 1
39  
40  time.sleep(2)
41  
42  # Draw a Smiley Face
43  matrix.fill(0)
44  
45  for row in range(2, 6):
46      matrix[row, 0] = 1
47      matrix[row, 7] = 1
48  
49  for column in range(2, 6):
50      matrix[0, column] = 1
51      matrix[7, column] = 1
52  
53  matrix[1, 1] = 1
54  matrix[1, 6] = 1
55  matrix[6, 1] = 1
56  matrix[6, 6] = 1
57  matrix[2, 5] = 1
58  matrix[5, 5] = 1
59  matrix[2, 3] = 1
60  matrix[5, 3] = 1
61  matrix[3, 2] = 1
62  matrix[4, 2] = 1
63  
64  # Move the Smiley Face Around
65  while True:
66      for frame in range(0, 8):
67          matrix.shift_right(True)
68          time.sleep(0.05)
69      for frame in range(0, 8):
70          matrix.shift_down(True)
71          time.sleep(0.05)
72      for frame in range(0, 8):
73          matrix.shift_left(True)
74          time.sleep(0.05)
75      for frame in range(0, 8):
76          matrix.shift_up(True)
77          time.sleep(0.05)