LED Strip
#Description
A LED strip is a chain of RGB (red-green-blue) LEDs connected together. Each LED's color and brightness can be controlled individually.
#Links
#Aliases
- RGB LED Strip
- Neopixel
- WS2813
- WS2812
#Functions
#JavaScript / Node.js
LEDStrip component for controlling addressable LED strips (NeoPixel/WS2812). Extends ComponentBase with LED strip-specific commands.
#Value type
interface LEDStripValue {
leds: { color: string }[];
}#Constructor options
| Option | Type | Required | Description |
|---|---|---|---|
pin | number | DigitalPin | required | — |
ledCount | number | optional | — |
colorOrder | string | optional | — |
gamma | number | optional | — |
#Events
| Event | Parameters | Description |
|---|---|---|
change | value: LEDStripValue | — |
#Methods
setColor(color: string)Set all LEDs to a single color.
setPixel(index: number, color: string)Set a single pixel to a color.
setRange(start: number, end: number, color: string)Set a range of pixels to a color.
setBrightness(value: number)Set the brightness of the strip.
shift(forward: boolean, wrap: boolean)Shift all pixels in a direction.
off()→ thisTurn all LEDs off (no arguments) or remove an event listener.
show()Commit buffered changes to the hardware.
get value→ LEDStripValue | undefinedfrom ComponentBaseGet the current value of the component.
#Example
import { Board, LEDStrip } from "@blokdots/components";
const board = new Board("/dev/ttyACM0");
await board.open();
const lEDStrip = new LEDStrip({ board, pin: "D5" });#C++ (Arduino)
Addressable LED strip using Adafruit NeoPixel (WS2812 / NeoPixel compatible) Optional trigger support: - If constructed with EventBus + evtChange, emits evtChange whenever the strip state changes - emittedValue(): returns last change "version" counter (monotonic int) NEW (non-breaking additions): - Supports blokdots::Color for whole-strip and per-pixel set/get - Optional representative strip color + per-pixel color getters - emittedColor(): returns a "representative" color snapshot (does NOT affect existing triggers)
#Required libraries
#include <Adafruit_NeoPixel.h>— Adafruit NeoPixel v1.15.2
#Setup
#include "blokdots.h"
LEDStrip myComponent(5, 0);#Constructor
LEDStrip(pin, numPixels, pixelType, startBrightness)Basic constructor (no EventBus)
| Parameter | Type | Default |
|---|---|---|
pin | uint8_t | required |
numPixels | uint16_t | required |
pixelType | neoPixelType | NEO_GRB + NEO_KHZ800 |
startBrightness | uint8_t | 255 |
LEDStrip(bus, pin, numPixels, evtChange, pixelType, startBrightness)Constructor with EventBus for trigger support
| Parameter | Type | Default |
|---|---|---|
bus | EventBus | required |
pin | uint8_t | required |
numPixels | uint16_t | required |
evtChange | uint8_t | required |
pixelType | neoPixelType | NEO_GRB + NEO_KHZ800 |
startBrightness | uint8_t | 255 |
#Methods
setBrightness(b)| Parameter | Type | Default |
|---|---|---|
b | uint8_t | required |
getBrightness()→ uint8_tclear()off()setColor(r, g, b)| Parameter | Type | Default |
|---|---|---|
r | uint8_t | required |
g | uint8_t | required |
b | uint8_t | required |
setColor(packedColor)| Parameter | Type | Default |
|---|---|---|
packedColor | uint32_t | required |
setColor(hex)Hex string: "#ff0000" or "ff0000"
| Parameter | Type | Default |
|---|---|---|
hex | const char | required |
setPixel(index, r, g, b)| Parameter | Type | Default |
|---|---|---|
index | uint16_t | required |
r | uint8_t | required |
g | uint8_t | required |
b | uint8_t | required |
setPixel(index, packedColor)| Parameter | Type | Default |
|---|---|---|
index | uint16_t | required |
packedColor | uint32_t | required |
setPixel(index, hex)| Parameter | Type | Default |
|---|---|---|
index | uint16_t | required |
hex | const char | required |
setPixel(index, c)NEW: blokdots::Color per-pixel
| Parameter | Type | Default |
|---|---|---|
index | uint16_t | required |
c | blokdots::Color | required |
size()→ uint16_tshift(direction, wrap)wrap: if true, shifted-out pixel reappears on the other side
| Parameter | Type | Default |
|---|---|---|
direction | bool | required |
wrap | bool | required |
show()emittedValue()→ intFor Arduino triggers: a numeric value that changes when the strip changes