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
17display = Seg14x4(i2c, auto_write=False)
18# Brightness of the display (0 to 15)
19display.brightness = 0.3
20
21ani = Animation(display)
22
23try:
24 text = "Init"
25
26 display.fill(1)
27 display.show()
28 sleep(1)
29 display.fill(0)
30 display.show()
31
32 display.print(text)
33 display.show()
34 sleep(2)
35 display.fill(0)
36 display.show()
37 sleep(1)
38
39 ani.count_down()
40 sleep(0.2)
41
42 text = "Go!!"
43
44 display.print(text)
45 display.show()
46 sleep(1.5)
47 display.fill(0)
48 display.show()
49 sleep(0.5)
50 print()
51
52 while True:
53 # Arrow
54 print("Arrow")
55 ani.animate([0, 1, 2], [192], 0.1)
56 ani.animate([3], [2368], 0.1)
57 sleep(1.0)
58 display.fill(0)
59 sleep(1.0)
60
61 # Flying
62 print("Flying")
63 cyc = 0
64
65 while cyc < 5:
66 ani.animate([0], [1280, 192, 10240, 192], 0.2)
67
68 cyc += 1
69
70 ani.animate([0], [0])
71 sleep(1.0)
72 display.fill(0)
73 sleep(1.0)
74
75 # Chase forward and reverse.
76 print("Chase forward and reverse")
77 ani.chase_forward_and_reverse(0.01, 5)
78 sleep(1.0)
79 display.fill(0)
80 sleep(1.0)
81
82 # Testing writing to more than one segment simultaneously
83 print("Prelude to Spinners")
84 ani.prelude_to_spinners(0.1, 5)
85 sleep(1.0)
86 display.fill(0)
87 display.show()
88 sleep(1.0)
89
90 print("Spinners")
91 ani.spinners(0.1, 20)
92 sleep(1.0)
93 display.fill(0)
94 display.show()
95 sleep(1.0)
96
97 print("Enclosed Spinners")
98 ani.enclosed_spinners(0.1, 20)
99 sleep(1.0)
100 display.fill(0)
101 display.show()
102 sleep(1.0)
103
104 print()
105except KeyboardInterrupt:
106 display.fill(0)
107 display.show()