Simple test¶
Ensure your device works with this simple test.
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
11import board
12import busio
13
14# Import the HT16K33 LED matrix module.
15from adafruit_ht16k33 import matrix
16
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)
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)
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)
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)
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""
5 Test script for display animations on an HT16K33 with alphanumeric display
6
7 The display must be initialized with auto_write=False.
8"""
9
10from time import sleep
11import board
12from adafruit_ht16k33.segments import Seg14x4
13from adafruit_ht16k33.animations import Animation
14
15# Initialize the I2C bus
16i2c = board.I2C() # uses board.SCL and board.SDA
17# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
18display = Seg14x4(i2c, auto_write=False)
19# Brightness of the display (0.0 to 1.0)
20display.brightness = 0.3
21
22ani = Animation(display)
23
24try:
25 text = "Init"
26
27 display.fill(1)
28 display.show()
29 sleep(1)
30 display.fill(0)
31 display.show()
32
33 display.print(text)
34 display.show()
35 sleep(2)
36 display.fill(0)
37 display.show()
38 sleep(1)
39
40 ani.count_down()
41 sleep(0.2)
42
43 text = "Go!!"
44
45 display.print(text)
46 display.show()
47 sleep(1.5)
48 display.fill(0)
49 display.show()
50 sleep(0.5)
51 print()
52
53 while True:
54 # Arrow
55 print("Arrow")
56 ani.animate([0, 1, 2], [192], 0.1)
57 ani.animate([3], [2368], 0.1)
58 sleep(1.0)
59 display.fill(0)
60 sleep(1.0)
61
62 # Flying
63 print("Flying")
64 cyc = 0
65
66 while cyc < 5:
67 ani.animate([0], [1280, 192, 10240, 192], 0.2)
68
69 cyc += 1
70
71 ani.animate([0], [0])
72 sleep(1.0)
73 display.fill(0)
74 sleep(1.0)
75
76 # Chase forward and reverse.
77 print("Chase forward and reverse")
78 ani.chase_forward_and_reverse(0.01, 5)
79 sleep(1.0)
80 display.fill(0)
81 sleep(1.0)
82
83 # Testing writing to more than one segment simultaneously
84 print("Prelude to Spinners")
85 ani.prelude_to_spinners(0.1, 5)
86 sleep(1.0)
87 display.fill(0)
88 display.show()
89 sleep(1.0)
90
91 print("Spinners")
92 ani.spinners(0.1, 20)
93 sleep(1.0)
94 display.fill(0)
95 display.show()
96 sleep(1.0)
97
98 print("Enclosed Spinners")
99 ani.enclosed_spinners(0.1, 20)
100 sleep(1.0)
101 display.fill(0)
102 display.show()
103 sleep(1.0)
104
105 print()
106except KeyboardInterrupt:
107 display.fill(0)
108 display.show()