ruban-neopixel.ino
A light head moves along a strip of 16 NeoPixel (WS2812B) LEDs with a red trail. Each LED is individually addressable over a single-wire protocol, driven by the Adafruit_NeoPixel library.
Hardware
An Arduino Pro Mini (ATmega328P, 5 V/16 MHz or 3.3 V/8 MHz variants) wired to a USB-serial adapter (FTDI) or an ICSP programmer. 1 NeoPixel (WS2812B) strip or ring, dedicated 5V supply recommended + 470-1000 µF capacitor across the supply.
Wiring
Strip data (DIN) to pin 6 (330 Ω resistor advised), VCC to 5V (or external 5V), GND common with the board.
How it works
setPixelColor() stacks colors in a buffer, show() sends the full frame. The head position advances and wraps with the modulo.
Running it
Select « Arduino Pro Mini » in the IDE (5 V/16 MHz or 3.3 V/8 MHz per your model), ATmega328P processor, the right port, then Upload. The adapter must be wired DTR-DTR, RX-TX, TX-RX, VCC-VCC, GND-GND.
Variants
The FastLED library for richer effects (Chase, Rainbow), or drive colors from a serial command received on Serial.
ruban-neopixel.ino
// Animation "marche" sur ruban NeoPixel (WS2812B).
#include <Adafruit_NeoPixel.h>
const int PIN = 6;
const int NB_LED = 16;
Adafruit_NeoPixel ruban(NB_LED, PIN, NEO_GRB + NEO_KHZ800);
int tete = 0;
void setup() {
ruban.begin();
ruban.setBrightness(60); // attention : 255 = jusque 3 A pour 60 LED !
Serial.begin(9600);
}
void loop() {
ruban.clear(); // eteint tout
// Une tete blanche + 4 cometes rouges qui se deplacent.
ruban.setPixelColor(tete, ruban.Color(255, 255, 255));
for (int i = 1; i <= 4; i++) {
int pos = (tete - i + NB_LED) % NB_LED;
ruban.setPixelColor(pos, ruban.Color(255 - i * 50, 0, 0));
}
ruban.show(); // une seule trame serial vers les LED
tete = (tete + 1) % NB_LED;
delay(80);
}