adafruit_trellism4
¶
CircuitPython library for the Trellis M4 Express.
- Author(s): Scott Shawcroft, Kattni Rembor
Implementation Notes¶
Hardware:
# Add link to Trellis M4 Express when product is released.
Software and Dependencies:
- Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
-
class
adafruit_trellism4.
TrellisM4Express
(rotation=0)¶ Represents a single Trellis M4 Express. Do not use more than one at a time.
Parameters: rotation – Allows for rotating the Trellis M4 Express in 90 degree increments to different positions and utilising the grid from that position. Supports 0
,90
,180
, and270
.0
degrees is when the USB facing away from you. Default is 0.import time import adafruit_trellism4 trellis = adafruit_trellism4.TrellisM4Express() current_press = set() while True: pressed = set(trellis.pressed_keys) for press in pressed - current_press: print("Pressed:", press) for release in current_press - pressed: print("Released:", release) time.sleep(0.08) current_press = pressed
-
pixels
= None¶ Sequence like object representing the 32 NeoPixels on the Trellis M4 Express, Provides a two dimensional representation of the NeoPixel grid.
This example lights up the first pixel green:
import adafruit_trellism4 trellis = adafruit_trellism4.TrellisM4Express() trellis.pixels[0, 0] = (0, 255, 0)
Options for
pixels
:pixels.fill
: Colors all the pixels a given color. Provide an (R, G, B) color tuple (such as (255, 0, 0) for red), or a hex color value (such as 0xff0000 for red).This example colors all pixels red:
import adafruit_trellism4 trellis = adafruit_trellism4.TrellisM4Express() trellis.pixels.fill((255, 0, 0))
pixels.width
andpixels.height
: The width and height of the grid. Whenrotation
is 0,width
is 8 andheight
is 4.This example colors all pixels blue:
import adafruit_trellism4 trellis = adafruit_trellism4.TrellisM4Express() for x in range(trellis.pixels.width): for y in range(trellis.pixels.height): trellis.pixels[x, y] = (0, 0, 255)
pixels.brightness
: The overall brightness of the pixel. Must be a number between 0 and 1, where the number represents a percentage between 0 and 100, i.e.0.3
is 30%.This example sets the brightness to
0.3
and turns all the LEDs red:import adafruit_trellism4 trellis = adafruit_trellism4.TrellisM4Express() trellis.pixels.brightness = 0.3 trellis.pixels.fill((255, 0, 0))
-
pressed_keys
¶ A list of tuples of currently pressed button coordinates.
import time import adafruit_trellism4 trellis = adafruit_trellism4.TrellisM4Express() current_press = set() while True: pressed = set(trellis.pressed_keys) for press in pressed - current_press: print("Pressed:", press) for release in current_press - pressed: print("Released:", release) time.sleep(0.08) current_press = pressed
-