ht16k33_matrix_pillow_image.py
1 # Basic example of drawing an image 2 # This example and library is meant to work with Adafruit CircuitPython API. 3 # 4 # This example is for use on (Linux) computers that are using CPython with 5 # Adafruit Blinka to support CircuitPython libraries. CircuitPython does 6 # not support PIL/pillow (python imaging library)! 7 # 8 # Author: Melissa LeBlanc-Williams 9 # License: Public Domain 10 11 # Import all board pins. 12 import board 13 import busio 14 from PIL import Image 15 16 # Import the HT16K33 LED matrix module. 17 from adafruit_ht16k33 import matrix 18 19 # Create the I2C interface. 20 i2c = busio.I2C(board.SCL, board.SDA) 21 22 # Create the matrix class. 23 # This creates a 16x8 matrix: 24 mtrx = matrix.Matrix16x8(i2c) 25 # Or this creates a 16x8 matrix backpack: 26 # mtrx = matrix.MatrixBackpack16x8(i2c) 27 # Or this creates a 8x8 matrix: 28 # mtrx = matrix.Matrix8x8(i2c) 29 # Or this creates a 8x8 bicolor matrix: 30 # mtrx = matrix.Matrix8x8x2(i2c) 31 # Finally you can optionally specify a custom I2C address of the HT16k33 like: 32 # mtrx = matrix.Matrix16x8(i2c, address=0x70) 33 34 if isinstance(mtrx, matrix.Matrix8x8x2): 35 image = Image.open("squares-color.png") 36 elif isinstance(mtrx, matrix.Matrix16x8): 37 image = Image.open("squares-mono-16x8.png") 38 else: 39 image = Image.open("squares-mono-8x8.png") 40 41 # Clear the matrix 42 mtrx.fill(0) 43 mtrx.image(image)