Skip to main content

LED Driver

You can start a driver for WS2812B, APA102, or SK9822 using startLed.

import { LedVariant, LedStripLightType } from "@devicescript/core"
import { startLed } from "@devicescript/drivers"
import { pins } from "@dsboard/adafruit_qt_py_c3"

const led = await startLed({
length: 32,
variant: LedVariant.Ring,
hwConfig: { type: LedStripLightType.WS2812B_GRB, pin: pins.A0_D0 },
})

Gamma correction

The Led supports Gamma correction, but it is disabled by default. Gamma correction is applied before rendering the colors to account for how our eyes sense the light created by LEDs.

const led = await startLed({
gamma: 2.8,
})

Topology

You can specify the topology of the LED strip by using the variant register. The default is a flexible strip but other popular options like ring are also available.

import { LedVariant } from "@devicescript/core"

const led = await startLed({
variant: LedVariant.Ring,
})

For LED matrix with row major, you should also specify the number of columns.

import { LedVariant } from "@devicescript/core"

const led = await startLed({
length: 64 // 8x8
variant: LedVariant.Matrix,
columns: 8
})

To work on the LEDs as it if was an image, use the startLedDisplay helper.

Maximum power consumption

A large number of LED consuming maximum power can lead to an impressive surge of power consumption. The LED driver allows to specify a maximum power (in watts) and a LED power consumption model. Given those information

const led = await startLed({
maxPower: 5, // watts
})