adafruit_trellis - Adafruit Trellis Monochrome 4x4 LED Backlit Keypad

CircuitPython library to support Adafruit’s Trellis Keypad.

  • Author(s): Limor Fried, Radomir Dopieralski, Tony DiCola,

    Scott Shawcroft, and Michael Schroeder

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_trellis.Trellis(i2c: I2C, addresses: List[int] | None = None)

Driver base for a single Trellis Board

Parameters:
Usage Example
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# Basic example of turning on LEDs and handling Keypad
 5# button activity.
 6
 7# This example uses only one Trellis board, so all loops assume
 8# a maximum of 16 LEDs (0-15). For use with multiple Trellis boards,
 9# see the documentation.
10
11import time
12import busio
13from board import SCL, SDA
14from adafruit_trellis import Trellis
15
16# Create the I2C interface
17i2c = busio.I2C(SCL, SDA)
18
19# Create a Trellis object
20trellis = Trellis(i2c)  # 0x70 when no I2C address is supplied
21
22# 'auto_show' defaults to 'True', so anytime LED states change,
23# the changes are automatically sent to the Trellis board. If you
24# set 'auto_show' to 'False', you will have to call the 'show()'
25# method afterwards to send updates to the Trellis board.
26
27# Turn on every LED
28print("Turning all LEDs on...")
29trellis.led.fill(True)
30time.sleep(2)
31
32# Turn off every LED
33print("Turning all LEDs off...")
34trellis.led.fill(False)
35time.sleep(2)
36
37# Turn on every LED, one at a time
38print("Turning on each LED, one at a time...")
39for i in range(16):
40    trellis.led[i] = True
41    time.sleep(0.1)
42
43# Turn off every LED, one at a time
44print("Turning off each LED, one at a time...")
45for i in range(15, 0, -1):
46    trellis.led[i] = False
47    time.sleep(0.1)
48
49# Now start reading button activity
50# - When a button is depressed (just_pressed),
51#   the LED for that button will turn on.
52# - When the button is relased (released),
53#   the LED will turn off.
54# - Any button that is still depressed (pressed_buttons),
55#   the LED will remain on.
56print("Starting button sensory loop...")
57pressed_buttons = set()
58while True:
59    # Make sure to take a break during each trellis.read_buttons
60    # cycle.
61    time.sleep(0.1)
62
63    just_pressed, released = trellis.read_buttons()
64    for b in just_pressed:
65        print("pressed:", b)
66        trellis.led[b] = True
67    pressed_buttons.update(just_pressed)
68    for b in released:
69        print("released:", b)
70        trellis.led[b] = False
71    pressed_buttons.difference_update(released)
72    for b in pressed_buttons:
73        print("still pressed:", b)
74        trellis.led[b] = True
property auto_show: bool

Current state of sending LED updates directly the Trellis board(s). True or False.

The current blink rate as an integer range 0-3.

property brightness: int

The current brightness as an integer range 0-15.

led

The LED object used to interact with Trellis LEDs.

  • trellis.led[x] returns the current LED status of LED x (True/False)

  • trellis.led[x] = True turns the LED at x on

  • trellis.led[x] = False turns the LED at x off

  • trellis.led.fill(bool) turns every LED on (True) or off (False)

read_buttons() Tuple[List[int], List[int]]

Read the button matrix register on the Trellis board(s). Returns two lists: 1 for new button presses, 1 for button relases.

show() None

Refresh the LED buffer and show the changes.