Trinkey QT2040
The Adafruit Trinkey QT2040 is the USB adapter that bridges StemmaQT devices to the browser. It is a RP2040-based USB stick with one onboard NeoPixel and a StemmaQT port for connecting I2C devices. See the Adafruit learn guide for hardware details.
Connection
Call startTrinkey() inside preload(). The Trinkey takes no arguments — there is only ever one connected at a time and it emits no events.
let trinkey;
function preload() {
trinkey = startTrinkey();
}Methods
Methods (NeoPixel)
getBrightness() number
Returns the current brightness level as an integer from 0 (off) to 255 (full brightness). The default is 128.
getLength() number
Returns the number of NeoPixels on the device.
getPixelColor(index?) ColorObject
Returns the last known color of the pixel at index (defaults to 0) as a { red, green, blue } object with values from 0 to 255.
getPixelColors(offset?, length?) ColorObject[]
Returns an array of { red, green, blue } objects for the pixels starting at offset (default 0). If length is omitted, all pixels from the offset to the end are returned.
setBrightness(value) Promise<void>
Sets the global brightness for all pixels. value is clamped to 0–255 and rounded to the nearest integer.
setPixelColor(color) Promise<void>
setPixelColor(index, color) Promise<void>
Sets the color of a single pixel. When called with one argument the first pixel (index 0) is used. color accepts a { red, green, blue } object, a CSS hex string (e.g. "#ff0000"), or a packed 24-bit integer.
setPixelColors(colors) Promise<void>
setPixelColors(offset, colors) Promise<void>
Sets the colors of multiple pixels in one call. When called with one argument the update starts at pixel 0; provide an offset to start further along. Each entry in colors accepts the same formats as setPixelColor. Large updates are automatically split into chunks of 64 pixels.
Methods (BaseDevice)
connect() Promise<Response>
Opens the USB connection and sends the start command to the firmware. Calling it multiple times is safe — subsequent calls return the same promise. In p5.js you do not need to call this manually; startXxx() calls it for you inside preload().
Properties
Properties (BaseDevice)
id { type, address }
Identifies the device. type is the DeviceType enum value, address is the I2C address the device was started with.
isConnected boolean
true once the USB connection has been established and the firmware has acknowledged the device. In p5.js this is always true by the time setup() runs, because startXxx() waits for the connection inside preload().