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.I2C
object 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
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
orFalse
.
- 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] = True
turns the LED atx
ontrellis.led[x] = False
turns the LED atx
offtrellis.led.fill(bool)
turns every LED on (True) or off (False)