Simple test

Ensure your device works with this simple test.

examples/display_ht16k33_simpletest.py
# Copied and adapted in ht16k33_matrix_simpletest.py example for the Adafruit_ht16k33 library here:

import time
import board
from display_ht16k33 import matrix

display = board.DISPLAY
matrix = matrix.Matrix8x8()
display.show(matrix.group)

for row in range(2, 6):
    matrix[row, 0] = 1
    matrix[row, 7] = 1

for column in range(2, 6):
    matrix[0, column] = 1
    matrix[7, column] = 1

matrix[1, 1] = 1
matrix[1, 6] = 1
matrix[6, 1] = 1
matrix[6, 6] = 1
matrix[2, 5] = 1
matrix[5, 5] = 1
matrix[2, 3] = 1
matrix[5, 3] = 1
matrix[3, 2] = 1
matrix[4, 2] = 1

# Move the Smiley Face Around
while True:
    for frame in range(0, 8):
        matrix.shift_right(True)
        time.sleep(0.05)
    for frame in range(0, 8):
        matrix.shift_down(True)
        time.sleep(0.05)
    for frame in range(0, 8):
        matrix.shift_left(True)
        time.sleep(0.05)
    for frame in range(0, 8):
        matrix.shift_up(True)
        time.sleep(0.05)

Text display example

Showing some text using framebuffer

examples/display_ht16k33_text.py
import board
import adafruit_framebuf
from display_ht16k33 import matrix

# Uncomment/Comment the following lines to select the size of your Matrix
col = 16
# col = 8

if col == 16:
    matrix = matrix.Matrix16x8()
else:
    matrix = matrix.Matrix8x8()

display = board.DISPLAY
display.show(matrix.group)


buf = bytearray(col)
text_to_show = "Hello :)"
fb = adafruit_framebuf.FrameBuffer(buf, col, 8, adafruit_framebuf.MVLSB)

while True:
    for i in range(len(text_to_show) * 8):
        fb.fill(0)
        fb.text(text_to_show, -i + col, 0, color=1)
        matrix.fill(0)
        for x in range(col):
            bite = buf[x]
            for y in range(8):
                bit = 1 << y & bite
                if bit:
                    matrix[col - x, y + 1] = 1

Segments Simple test

Segments simple test

examples/display_ht16k33_segments_simpletest.py
# Adafruit_ht16k33 library here:
# https://github.com/adafruit/Adafruit_CircuitPython_HT16K33

import time
import board
from display_ht16k33.segments import SEG7x4

display = board.DISPLAY

my_segment = SEG7x4(40, 40)

display.show(my_segment.group)

# Clear the display.
my_segment.fill(0)

# Can just print a number
my_segment.print(42)
time.sleep(2)

# Or, print the time
my_segment.print("12:30")
time.sleep(2)

my_segment.colon = False

# Or, can set indivdual digits / characters
# Set the first character to '1':
my_segment[0] = "1"
# Set the second character to '2':
my_segment[1] = "2"
# Set the third character to 'A':
my_segment[2] = "A"
# Set the forth character to 'B':
my_segment[3] = "B"
time.sleep(2)

# Or, can even set the segments to make up characters
if isinstance(my_segment, SEG7x4):
    # 7-segment raw digits
    my_segment.set_digit_raw(0, 0xFF)
    my_segment.set_digit_raw(1, 0b11111111)
    my_segment.set_digit_raw(2, 0x79)
    my_segment.set_digit_raw(3, 0b01111001)

Segment Countdown example

Segment countdown example

examples/display_ht16k33_segments_count_down.py
import time
import board
from display_ht16k33.segments import SEG7x4

display = board.DISPLAY

my_segment = SEG7x4(40, 40)

display.show(my_segment.group)

for i in range(100, 0, -1):
    my_segment.print(i)
    time.sleep(1)

Segment Custom Chars example

Segment Custom Chats example

examples/display_ht16k33_segments_custom_chars.py
import board
from display_ht16k33.segments import SEG7x4

display = board.DISPLAY

custom_chars = {}

# Add the custom characters you want
custom_chars["s"] = 0b01101101
custom_chars["r"] = 0b01010000
custom_chars["o"] = 0b00111111
custom_chars["l"] = 0b00110000
custom_chars["i"] = 0b00010000
custom_chars["n"] = 0b01010100
custom_chars["g"] = 0b01101111

my_segment = SEG7x4(40, 40, char_dict=custom_chars)

display.show(my_segment.group)
my_segment.print("sing")

Segment 14x4 example

Segment 14x4 example

examples/display_ht16k33_segments_14x4.py
import board
import displayio
from display_ht16k33.segments import SEG14x4

display = board.DISPLAY
group = displayio.Group()

my_segment = SEG14x4(40, 40)

group.append(my_segment.group)
my_segment.print("12:30")

display.show(group)

Marquee 14x4 example

Marquee 14x4 example

examples/display_ht16k33_segments_marquee.py
import board
import displayio
from display_ht16k33.segments import SEG14x4

display = board.DISPLAY
group = displayio.Group()

my_segment = SEG14x4(40, 40)

group.append(my_segment.group)
display.show(group)
my_segment.marquee("This is an example :)", delay=0.35, loop=True)

Advanced Example

Advanced Example

examples/display_ht16k33_advanced_example.py
import time
import board
import displayio
from display_ht16k33.matrix import Matrix8x8
from display_ht16k33.segments import SEG7x4, SEG14x4


display = board.DISPLAY
general_group = displayio.Group()
my_matrix = Matrix8x8(30, 25, 5, False)
my_segment2 = SEG14x4(30, 150, color_on=0x40B080, color_off=0x121212)
my_segment = SEG7x4(150, 40, height=20, length=20, space=35, color_on=0x00FF10)

general_group.append(my_matrix.group)
general_group.append(my_segment2.group)
general_group.append(my_segment.group)
display.show(general_group)

for row in range(2, 6):
    my_matrix[row, 0] = 1
    my_matrix[row, 7] = 1

for column in range(2, 6):
    my_matrix[0, column] = 1
    my_matrix[7, column] = 1

my_matrix[1, 1] = 1
my_matrix[1, 6] = 1
my_matrix[6, 1] = 1
my_matrix[6, 6] = 1
my_matrix[2, 5] = 1
my_matrix[5, 5] = 1
my_matrix[2, 3] = 1
my_matrix[5, 3] = 1
my_matrix[3, 2] = 1
my_matrix[4, 2] = 1

my_segment2.non_blocking_marquee("   This is an example", delay=0.35, loop=True)

# Move the Smiley Face Around
while True:
    for frame in range(0, 8):
        my_matrix.shift_right(True)
        time.sleep(0.05)
    my_segment.print(1111)
    my_segment2.non_blocking_marquee_update()
    for frame in range(0, 8):
        my_matrix.shift_down(True)
        time.sleep(0.05)
    my_segment.print(2222)
    my_segment2.non_blocking_marquee_update()
    for frame in range(0, 8):
        my_matrix.shift_left(True)
        time.sleep(0.05)
    my_segment.print(3333)
    my_segment2.non_blocking_marquee_update()
    for frame in range(0, 8):
        my_matrix.shift_up(True)
        time.sleep(0.05)
    my_segment.print(4444)
    my_segment2.non_blocking_marquee_update()

FrameBuffer Example

FrameBuffer Example

examples/display_ht16k33_frame_buffer_example.py
import board
import adafruit_framebuf
from display_ht16k33 import matrix


# col = 16
col = 8

if col == 16:
    matrix = matrix.Matrix16x8(50, 60, 8, True)
else:
    matrix = matrix.Matrix8x8(50, 60, 8, True)

display = board.DISPLAY
display.show(matrix.group)

buf = bytearray(col)
fb = adafruit_framebuf.FrameBuffer(buf, col, 16, adafruit_framebuf.MVLSB)

fb.line(0, 0, 0, 7, 0xFFFFFF)
fb.line(col - 1, 0, col - 1, 7, 0xFF0000)
fb.line(0, 7, col - 1, 7, 0xFF0000)
fb.line(0, 0, col - 1, 0, 0xFF0000)

fb.rect(col // 2 - 2, 3, 3, 3, 0xFF0000)
fb.rect(col // 2 + 1, 1, 2, 2, 0xFF0000)

for x in range(col):
    bite = buf[x]
    for y in range(8):
        bit = 1 << y & bite
        if bit:
            matrix[col - x - 1, y] = 1