Matrix 8x8 Pixel

CircuitPython Code

The following example will illuminate the matrix rows and columns one pixel at a time.

# Import all board pins.
import time
import board
import busio
from adafruit_ht16k33 import matrix

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

# creates a 8x8 matrix:
matrix = matrix.Matrix8x8(i2c)

# edges of an 8x8 matrix
col_max = 8
row_max = 8

# Clear the matrix.
matrix.fill(0)
col = 0
row = 0

while True:

    # illuminate a column one LED at a time
    while col < col_max:
        matrix[row, col] = 2
        col += 1
        time.sleep(.2)

    # next row when previous column is full
    if row < row_max:
        row += 1
        col = 0

    # clear matrix, start over
    else:
        row = col = 0
        matrix.fill(0)

Download and Run the Code

We can easily copy this code onto our Pi's home directory using the 'wget' command and then run it using the following commands.

Download: file
cd
wget https://raw.githubusercontent.com/adafruit/Adafruit_Learning_System_Guides/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/matrix8x8_test.py
python3 ./matrix8x8_test.py
Which should result in something like the following:
This guide was first published on Aug 24, 2012. It was last updated on Aug 24, 2012. This page (Matrix 8x8 Pixel) was last updated on Sep 19, 2019.