neopixel
ts
import {NeoPixel} from 'mikrojs/neopixel'Drive WS2812 (RGB) and SK6812 (RGBW) addressable LED strips.
Usage
ts
import {NeoPixel} from 'mikrojs/neopixel'
const strip = new NeoPixel(8, {count: 24})
strip.fill(255, 0, 0).orPanic('fill failed') // all red
strip.show().orPanic('show failed') // push to hardware
strip.setPixel(0, 0, 255, 0).orPanic('set failed') // first pixel green
strip.show().orPanic('show failed')
strip.clear().orPanic('clear failed') // all off
strip.end().orPanic('end failed') // release hardwareConstructor
new NeoPixel(pin, options)
ts
new NeoPixel(pin: number, options: NeoPixelOptions)Parameters:
pin: GPIO pin connected to the strip's data lineoptions: see NeoPixelOptions
Methods
strip.setPixel(index, r, g, b, w?)
ts
setPixel(index: number, r: number, g: number, b: number, w?: number): Result<void, NeoPixelError>Set a single pixel's color. Values are 0–255 per channel. The w parameter is only used with RGBW strips.
strip.fill(r, g, b, w?)
ts
fill(r: number, g: number, b: number, w?: number): Result<void, NeoPixelError>Set all pixels to the same color.
strip.show()
ts
show(): Result<void, NeoPixelError>Transmit the pixel buffer to the strip. Colors set via setPixel and fill are not visible until show() is called.
strip.clear()
ts
clear(): Result<void, NeoPixelError>Turn off all pixels and transmit (equivalent to fill(0, 0, 0) + show()).
strip.end()
ts
end(): Result<void, NeoPixelError>Release the RMT hardware channel. Call this when done with the strip.
Types
NeoPixelOptions
ts
interface NeoPixelOptions {
count: number // number of LEDs
rgbw?: boolean // true for SK6812 RGBW strips (default: false)
}Errors
NeoPixelError
| Variant | Fields | Description |
|---|---|---|
NotActive | — | Strip has been ended |
IndexOutOfRange | — | Pixel index >= count |
ShowFailed | message | Failed to transmit data |
NeoPixel is a registered trademark of Adafruit Industries.