Skip to main content

LED Strip

Digital
output
High RAM
2.1.0

#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.

#Aliases

  • RGB LED Strip
  • Neopixel
  • WS2813
  • WS2812

#Functions



#JavaScript / Node.js

ClassLEDStripextends ComponentBase

LEDStrip component for controlling addressable LED strips (NeoPixel/WS2812). Extends ComponentBase with LED strip-specific commands.

#Value type

TypeScript
interface LEDStripValue {
  leds: { color: string }[];
}

#Constructor options

OptionTypeRequiredDescription
pinnumber | DigitalPinrequired
ledCountnumberoptional
colorOrderstringoptional
gammanumberoptional

#Events

EventParametersDescription
changevalue: 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()this

Turn all LEDs off (no arguments) or remove an event listener.

show()

Commit buffered changes to the hardware.

get valueLEDStripValue | undefinedfrom ComponentBase

Get the current value of the component.

#Example

JavaScript
import { Board, LEDStrip } from "@blokdots/components";

const board = new Board("/dev/ttyACM0");
await board.open();

const lEDStrip = new LEDStrip({ board, pin: "D5" });


#C++ (Arduino)

ClassLEDStripextends ComponentBase

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

#Setup

C++
#include "blokdots.h"

LEDStrip myComponent(5, 0);

#Constructor

LEDStrip(pin, numPixels, pixelType, startBrightness)

Basic constructor (no EventBus)

ParameterTypeDefault
pinuint8_trequired
numPixelsuint16_trequired
pixelTypeneoPixelTypeNEO_GRB + NEO_KHZ800
startBrightnessuint8_t255
LEDStrip(bus, pin, numPixels, evtChange, pixelType, startBrightness)

Constructor with EventBus for trigger support

ParameterTypeDefault
busEventBusrequired
pinuint8_trequired
numPixelsuint16_trequired
evtChangeuint8_trequired
pixelTypeneoPixelTypeNEO_GRB + NEO_KHZ800
startBrightnessuint8_t255

#Methods

setBrightness(b)
ParameterTypeDefault
buint8_trequired
getBrightness()uint8_t
clear()
off()
setColor(r, g, b)
ParameterTypeDefault
ruint8_trequired
guint8_trequired
buint8_trequired
setColor(packedColor)
ParameterTypeDefault
packedColoruint32_trequired
setColor(hex)

Hex string: "#ff0000" or "ff0000"

ParameterTypeDefault
hexconst charrequired
setColor(c)

NEW: blokdots::Color whole-strip

ParameterTypeDefault
cblokdots::Colorrequired
setPixel(index, r, g, b)
ParameterTypeDefault
indexuint16_trequired
ruint8_trequired
guint8_trequired
buint8_trequired
setPixel(index, packedColor)
ParameterTypeDefault
indexuint16_trequired
packedColoruint32_trequired
setPixel(index, hex)
ParameterTypeDefault
indexuint16_trequired
hexconst charrequired
setPixel(index, c)

NEW: blokdots::Color per-pixel

ParameterTypeDefault
indexuint16_trequired
cblokdots::Colorrequired
size()uint16_t
shift(direction, wrap)

wrap: if true, shifted-out pixel reappears on the other side

ParameterTypeDefault
directionboolrequired
wrapboolrequired
show()
emittedValue()int

For Arduino triggers: a numeric value that changes when the strip changes