Simple test
Ensure your device works with this simple test.
examples/ht16k33_matrix_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4# Basic example of clearing and drawing a pixel on a LED matrix display.
5# This example and library is meant to work with Adafruit CircuitPython API.
6# Author: Tony DiCola
7# License: Public Domain
8
9# Import all board pins.
10import time
11
12import board
13import busio
14
15# Import the HT16K33 LED matrix module.
16from adafruit_ht16k33 import matrix
17
18# Create the I2C interface.
19i2c = busio.I2C(board.SCL, board.SDA)
20
21# Create the matrix class.
22# This creates a 16x8 matrix:
23matrix = matrix.Matrix16x8(i2c)
24# Or this creates a 16x8 matrix backpack:
25# matrix = matrix.MatrixBackpack16x8(i2c)
26# Or this creates a 8x8 matrix:
27# matrix = matrix.Matrix8x8(i2c)
28# Or this creates a 8x8 bicolor matrix:
29# matrix = matrix.Matrix8x8x2(i2c)
30# Finally you can optionally specify a custom I2C address of the HT16k33 like:
31# matrix = matrix.Matrix16x8(i2c, address=0x70)
32
33# Clear the matrix.
34matrix.fill(0)
35
36# Set a pixel in the origin 0, 0 position.
37matrix[0, 0] = 1
38# Set a pixel in the middle 8, 4 position.
39matrix[8, 4] = 1
40# Set a pixel in the opposite 15, 7 position.
41matrix[15, 7] = 1
42
43time.sleep(2)
44
45# Draw a Smiley Face
46matrix.fill(0)
47
48for row in range(2, 6):
49 matrix[row, 0] = 1
50 matrix[row, 7] = 1
51
52for column in range(2, 6):
53 matrix[0, column] = 1
54 matrix[7, column] = 1
55
56matrix[1, 1] = 1
57matrix[1, 6] = 1
58matrix[6, 1] = 1
59matrix[6, 6] = 1
60matrix[2, 5] = 1
61matrix[5, 5] = 1
62matrix[2, 3] = 1
63matrix[5, 3] = 1
64matrix[3, 2] = 1
65matrix[4, 2] = 1
66
67# Move the Smiley Face Around
68while True:
69 for frame in range(0, 8):
70 matrix.shift_right(True)
71 time.sleep(0.05)
72 for frame in range(0, 8):
73 matrix.shift_down(True)
74 time.sleep(0.05)
75 for frame in range(0, 8):
76 matrix.shift_left(True)
77 time.sleep(0.05)
78 for frame in range(0, 8):
79 matrix.shift_up(True)
80 time.sleep(0.05)
examples/ht16k33_segments_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4# Basic example of setting digits on a LED segment display.
5# This example and library is meant to work with Adafruit CircuitPython API.
6# Author: Tony DiCola
7# License: Public Domain
8
9import time
10
11# Import all board pins.
12import board
13import busio
14
15# Import the HT16K33 LED segment module.
16from adafruit_ht16k33 import segments
17
18# Create the I2C interface.
19i2c = busio.I2C(board.SCL, board.SDA)
20
21# Create the LED segment class.
22# This creates a 7 segment 4 character display:
23display = segments.Seg7x4(i2c)
24# Or this creates a 14 segment alphanumeric 4 character display:
25# display = segments.Seg14x4(i2c)
26# Or this creates a big 7 segment 4 character display
27# display = segments.BigSeg7x4(i2c)
28# Finally you can optionally specify a custom I2C address of the HT16k33 like:
29# display = segments.Seg7x4(i2c, address=0x70)
30
31# Clear the display.
32display.fill(0)
33
34# Can just print a number
35display.print(42)
36time.sleep(2)
37
38# Or, can print a hexadecimal value
39display.print_hex(0xFF23)
40time.sleep(2)
41
42# Or, print the time
43display.print("12:30")
44time.sleep(2)
45
46display.colon = False
47
48# Or, can set indivdual digits / characters
49# Set the first character to '1':
50display[0] = "1"
51# Set the second character to '2':
52display[1] = "2"
53# Set the third character to 'A':
54display[2] = "A"
55# Set the forth character to 'B':
56display[3] = "B"
57time.sleep(2)
58
59# Or, can even set the segments to make up characters
60if isinstance(display, segments.Seg7x4):
61 # 7-segment raw digits
62 display.set_digit_raw(0, 0xFF)
63 display.set_digit_raw(1, 0b11111111)
64 display.set_digit_raw(2, 0x79)
65 display.set_digit_raw(3, 0b01111001)
66else:
67 # 14-segment raw digits. Same character (0) displayed using four different methods.
68 # 16-bit Hexadecimal number
69 display.set_digit_raw(0, 0x2D3F)
70 # 16-bit Binary number
71 display.set_digit_raw(1, 0b0010110100111111)
72 # 8-bit Binary Tuple
73 display.set_digit_raw(2, (0b00101101, 0b00111111))
74 # 8-bit Hexadecimal List
75 display.set_digit_raw(3, [0x2D, 0x3F])
76time.sleep(2)
77
78# Show a looping marquee
79display.marquee("Deadbeef 192.168.100.102... ", 0.2)
examples/ht16k33_bicolor24_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4# Basic example of using the Bi-color 24 segment bargraph display.
5# This example and library is meant to work with Adafruit CircuitPython API.
6# Author: Carter Nelson
7# License: Public Domain
8
9import time
10
11# Import board related modules
12import board
13import busio
14
15# Import the Bicolor24 driver from the HT16K33 module
16from adafruit_ht16k33.bargraph import Bicolor24
17
18# Create the I2C interface
19i2c = busio.I2C(board.SCL, board.SDA)
20
21# Create the LED bargraph class.
22bc24 = Bicolor24(i2c)
23
24# Set individual segments of bargraph
25bc24[0] = bc24.LED_RED
26bc24[1] = bc24.LED_GREEN
27bc24[2] = bc24.LED_YELLOW
28
29time.sleep(2)
30
31# Turn them all off
32bc24.fill(bc24.LED_OFF)
33
34# Turn them on in a loop
35for i in range(24):
36 bc24[i] = bc24.LED_RED
37 time.sleep(0.1)
38 bc24[i] = bc24.LED_OFF
39
40time.sleep(1)
41
42# Fill the entrire bargraph
43bc24.fill(bc24.LED_GREEN)
examples/ht16k33_matrix_pillow_image.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4# Basic example of drawing an image
5# This example and library is meant to work with Adafruit CircuitPython API.
6#
7# This example is for use on (Linux) computers that are using CPython with
8# Adafruit Blinka to support CircuitPython libraries. CircuitPython does
9# not support PIL/pillow (python imaging library)!
10#
11# Author: Melissa LeBlanc-Williams
12# License: Public Domain
13
14# Import all board pins.
15import board
16import busio
17from PIL import Image
18
19# Import the HT16K33 LED matrix module.
20from adafruit_ht16k33 import matrix
21
22# Create the I2C interface.
23i2c = busio.I2C(board.SCL, board.SDA)
24
25# Create the matrix class.
26# This creates a 16x8 matrix:
27mtrx = matrix.Matrix16x8(i2c)
28# Or this creates a 16x8 matrix backpack:
29# mtrx = matrix.MatrixBackpack16x8(i2c)
30# Or this creates a 8x8 matrix:
31# mtrx = matrix.Matrix8x8(i2c)
32# Or this creates a 8x8 bicolor matrix:
33# mtrx = matrix.Matrix8x8x2(i2c)
34# Finally you can optionally specify a custom I2C address of the HT16k33 like:
35# mtrx = matrix.Matrix16x8(i2c, address=0x70)
36
37if isinstance(mtrx, matrix.Matrix8x8x2):
38 image = Image.open("squares-color.png")
39elif isinstance(mtrx, matrix.Matrix16x8):
40 image = Image.open("squares-mono-16x8.png")
41else:
42 image = Image.open("squares-mono-8x8.png")
43
44# Clear the matrix
45mtrx.fill(0)
46mtrx.image(image)
examples/ht16k33_animation_demo.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""
5Test script for display animations on an HT16K33 with alphanumeric display
6
7The display must be initialized with auto_write=False.
8"""
9
10from time import sleep
11
12import board
13
14from adafruit_ht16k33.animations import Animation
15from adafruit_ht16k33.segments import Seg14x4
16
17# Initialize the I2C bus
18i2c = board.I2C() # uses board.SCL and board.SDA
19# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
20display = Seg14x4(i2c, auto_write=False)
21# Brightness of the display (0.0 to 1.0)
22display.brightness = 0.3
23
24ani = Animation(display)
25
26try:
27 text = "Init"
28
29 display.fill(1)
30 display.show()
31 sleep(1)
32 display.fill(0)
33 display.show()
34
35 display.print(text)
36 display.show()
37 sleep(2)
38 display.fill(0)
39 display.show()
40 sleep(1)
41
42 ani.count_down()
43 sleep(0.2)
44
45 text = "Go!!"
46
47 display.print(text)
48 display.show()
49 sleep(1.5)
50 display.fill(0)
51 display.show()
52 sleep(0.5)
53 print()
54
55 while True:
56 # Arrow
57 print("Arrow")
58 ani.animate([0, 1, 2], [192], 0.1)
59 ani.animate([3], [2368], 0.1)
60 sleep(1.0)
61 display.fill(0)
62 sleep(1.0)
63
64 # Flying
65 print("Flying")
66 cyc = 0
67
68 while cyc < 5:
69 ani.animate([0], [1280, 192, 10240, 192], 0.2)
70
71 cyc += 1
72
73 ani.animate([0], [0])
74 sleep(1.0)
75 display.fill(0)
76 sleep(1.0)
77
78 # Chase forward and reverse.
79 print("Chase forward and reverse")
80 ani.chase_forward_and_reverse(0.01, 5)
81 sleep(1.0)
82 display.fill(0)
83 sleep(1.0)
84
85 # Testing writing to more than one segment simultaneously
86 print("Prelude to Spinners")
87 ani.prelude_to_spinners(0.1, 5)
88 sleep(1.0)
89 display.fill(0)
90 display.show()
91 sleep(1.0)
92
93 print("Spinners")
94 ani.spinners(0.1, 20)
95 sleep(1.0)
96 display.fill(0)
97 display.show()
98 sleep(1.0)
99
100 print("Enclosed Spinners")
101 ani.enclosed_spinners(0.1, 20)
102 sleep(1.0)
103 display.fill(0)
104 display.show()
105 sleep(1.0)
106
107 print()
108except KeyboardInterrupt:
109 display.fill(0)
110 display.show()