ruban-neopixel.ino
A sinusoidal blue-green gradient slides over 24 NeoPixel LEDs. The Teensy fast 32-bit CPU computes floating-point colors at 25 fps with ease, which an AVR cannot afford.
Hardware
A Teensy 4.1 (NXP i.MX RT1062, Cortex-M7 @ 600 MHz, 3.3 V logic, Ethernet and extra flash storage) powered over USB. 1 strip of 24 NeoPixel (WS2812B) LEDs + external 5 V supply.
Wiring
Data to pin 22 (330 Ω resistor), VCC to external 5 V, GND common with the Teensy (5 V tolerant data pin).
How it works
setPixelColor fills the buffer, show() sends the WS2812 frame. The per-index sinusoidal phase creates a continuous wave animated at 25 Hz.
Running it
Teensyduino in the Arduino IDE, « Teensy 4.1 » board, Upload then the Teensy Loader button. 3.3 V pins; the 4.1 adds Ethernet, USB host and extra pins.
Variants
Use the Audio library to sync colors to a microphone, or FastLED for ready-made effects.
ruban-neopixel.ino
// Ruban NeoPixel via la bibliotheque Adafruit_NeoPixel (core Teensy OK).
#include <Adafruit_NeoPixel.h>
const int PIN = 22;
const int NB = 24;
Adafruit_NeoPixel ruban(NB, PIN, NEO_GRB + NEO_KHZ800);
uint32_t bleu = ruban.Color(0, 0, 200);
uint32_t vert = ruban.Color(0, 200, 0);
unsigned long t0 = 0;
void setup() {
ruban.begin();
ruban.setBrightness(80);
Serial.begin(9600);
}
void loop() {
if (millis() - t0 < 40) return;
t0 = millis();
static float phase = 0;
phase += 0.08;
for (int i = 0; i < NB; i++) {
// Gradient deplace : interpolation sinusoidale bleu/vert.
float x = 0.5 + 0.5 * sinf(phase + i * 0.35);
uint8_t r = 0;
uint8_t g = (uint8_t)(x * 255);
uint8_t b = (uint8_t)((1.0 - x) * 255);
ruban.setPixelColor(i, ruban.Color(r, g, b));
}
ruban.show();
}