NeoPixel Rainbow Chaser
Simulate individually addressable RGB strips. This project demonstrates how to orchestrate a 12-LED WS2812B strip to create a moving color chaser effect using the high-level Intarva SDK.
Project Goal: Drive a 12-LED NeoPixel strip on GP15. The logic generates a random RGB value and “chases” it down the strip, clearing previous pixels as it advances.
1. Wiring Blueprint
| From Component | NeoPixel Pin | Pico Pin | Notes |
|---|---|---|---|
| WS2812B Strip | DIN | GP15 | Single-wire Data In |
| WS2812B Strip | 5V / VCC | VBUS | Power Rail (5V) |
| WS2812B Strip | GND | GND | Common Ground |
2. JavaScript Implementation
This project leverages the native NEOPIXEL_WRITE event for high-performance color updates.
JavaScript (SDK)
import intarva, { Pin, sleep } from 'intarva';
async function main() {
const NUM_LEDS = 12;
const dinPin = 'GP15';
// High-Level SDK Helper for NeoPixel Arrays
function show(colors) {
intarva.native.emit('NEOPIXEL_WRITE', {
pin: dinPin,
colors: colors
});
}
let currentLed = 0;
// Generate random [R, G, B] color
function getRandomColor() {
return [
Math.floor(Math.random() * 256),
Math.floor(Math.random() * 256),
Math.floor(Math.random() * 256)
];
}
while (true) {
const stripColors = [];
const activeColor = getRandomColor();
for (let i = 0; i < NUM_LEDS; i++) {
stripColors.push(i === currentLed ? activeColor : [0, 0, 0]);
}
show(stripColors);
currentLed = (currentLed + 1) % NUM_LEDS; // Chaser cycle
await sleep(150); // Speed control
}
}
main().catch(err => console.error(err));