ruban-neopixel.ino

Arduino UNO R3 · File : ruban-neopixel.ino · Language : Arduino · Use case : Animation arc-en-ciel sur ruban d'adresseables NeoPixel

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 Uno R3 (ATmega328P, 5 V, 16 MHz) powered over USB or a 7-12 V barrel jack. 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

In the Arduino IDE, select the « Arduino Uno » board and the matching serial port, then click Upload. Open the serial monitor at 9600 baud to follow the messages.

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);
}

← Back to the board