API Reference
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:
Adafruit Trellis Monochrome 4x4 LED Backlit Keypad (Product ID: 1616)
Software and Dependencies:
Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards: https://github.com/adafruit/circuitpython/releases
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
- class adafruit_trellis.Trellis(i2c: I2C, addresses: List[int] | None = None)
Driver base for a single Trellis Board
- Parameters:
i2c (I2C) – The
busio.I2Cobject to use. This is the only required parameter when using a single Trellis board.addresses (list) – The I2C address(es) of the Trellis board(s) you’re using. Defaults to
[0x70]which is the default address for Trellis boards. See Trellis product guide for using different/multiple I2C addresses. https://learn.adafruit.com/adafruit-trellis-diy-open-source-led-keypad
Usage Example1# 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 12 13import busio 14from board import SCL, SDA 15 16from adafruit_trellis import Trellis 17 18# Create the I2C interface 19i2c = busio.I2C(SCL, SDA) 20 21# Create a Trellis object 22trellis = Trellis(i2c) # 0x70 when no I2C address is supplied 23 24# 'auto_show' defaults to 'True', so anytime LED states change, 25# the changes are automatically sent to the Trellis board. If you 26# set 'auto_show' to 'False', you will have to call the 'show()' 27# method afterwards to send updates to the Trellis board. 28 29# Turn on every LED 30print("Turning all LEDs on...") 31trellis.led.fill(True) 32time.sleep(2) 33 34# Turn off every LED 35print("Turning all LEDs off...") 36trellis.led.fill(False) 37time.sleep(2) 38 39# Turn on every LED, one at a time 40print("Turning on each LED, one at a time...") 41for i in range(16): 42 trellis.led[i] = True 43 time.sleep(0.1) 44 45# Turn off every LED, one at a time 46print("Turning off each LED, one at a time...") 47for i in range(15, 0, -1): 48 trellis.led[i] = False 49 time.sleep(0.1) 50 51# Now start reading button activity 52# - When a button is depressed (just_pressed), 53# the LED for that button will turn on. 54# - When the button is relased (released), 55# the LED will turn off. 56# - Any button that is still depressed (pressed_buttons), 57# the LED will remain on. 58print("Starting button sensory loop...") 59pressed_buttons = set() 60while True: 61 # Make sure to take a break during each trellis.read_buttons 62 # cycle. 63 time.sleep(0.1) 64 65 just_pressed, released = trellis.read_buttons() 66 for b in just_pressed: 67 print("pressed:", b) 68 trellis.led[b] = True 69 pressed_buttons.update(just_pressed) 70 for b in released: 71 print("released:", b) 72 trellis.led[b] = False 73 pressed_buttons.difference_update(released) 74 for b in pressed_buttons: 75 print("still pressed:", b) 76 trellis.led[b] = True
- property auto_show: bool
Current state of sending LED updates directly the Trellis board(s).
TrueorFalse.
- led
The LED object used to interact with Trellis LEDs.
trellis.led[x]returns the current LED status of LEDx(True/False)trellis.led[x] = Trueturns the LED atxontrellis.led[x] = Falseturns the LED atxofftrellis.led.fill(bool)turns every LED on (True) or off (False)