FluxBench.AIShared project · read-only

NeoPixel Ring Animations

ESP32 DevKit (WROOM-32)·Arduino C++·Updated Jul 27, 2026·by FluxBench TeamIncludes Lab + Schematic

Three animations on a 16-LED WS2812B NeoPixel ring: a rotating rainbow, a cyan comet with a fading tail, and a purple breathe effect. Click the bench push button (GPIO 14) to cycle rainbow → comet → breathe → off, and drag the potentiometer (GPIO 34) to set the animation speed live — the virtual ring on the bench and the pixel strip panel both animate in real time. Everything runs on plain Adafruit_NeoPixel calls, so the same sketch drops straight onto real hardware.

sketch.ino
// NeoPixel Ring Animations - cycle patterns with the button, set the speed with the pot.
// Click the bench push button (GPIO 14) to switch rainbow -> comet -> breathe -> off.
// Drag the potentiometer (GPIO 34) to change the animation speed while it runs.

#include <Adafruit_NeoPixel.h>

#define RING_PIN 5
#define BTN_PIN 14
#define POT_PIN 34
#define NUM_PIXELS 16

Adafruit_NeoPixel ring(NUM_PIXELS, RING_PIN, NEO_GRB + NEO_KHZ800);

int mode = 0;              // 0 rainbow, 1 comet, 2 breathe, 3 off
int lastBtn = HIGH;
int step = 0;
unsigned long lastFrame = 0;

void printMode() {
  if (mode == 0) Serial.println("mode: rainbow");
  else if (mode == 1) Serial.println("mode: comet");
  else if (mode == 2) Serial.println("mode: breathe");
  else Serial.println("mode: off");
}

void drawFrame() {
  if (mode == 0) {
    // rainbow: a full hue wheel spread over the ring, rotating each frame
    for (int i = 0; i < NUM_PIXELS; i++) {
      int hue = (i * 4096 + step * 1024) % 65536;
      ring.setPixelColor(i, ring.ColorHSV(hue, 255, 200));
    }
  } else if (mode == 1) {
    // comet: a bright cyan head with a fading tail chasing around the ring
    ring.clear();
    int head = step % NUM_PIXELS;
    for (int t = 0; t < 6; t++) {
      int i = (head - t + NUM_PIXELS + NUM_PIXELS) % NUM_PIXELS;
      int v = 220 - t * 38;
      ring.setPixelColor(i, ring.Color(0, v, v));
    }
  } else if (mode == 2) {
    // breathe: the whole ring fades purple in and out
    int phase = step % 60;
    int v = phase < 30 ? phase * 8 : (60 - phase) * 8;
    ring.fill(ring.Color(v, 0, v), 0, NUM_PIXELS);
  } else {
    ring.clear();
  }
  ring.show();
}

void setup() {
  Serial.begin(115200);
  pinMode(BTN_PIN, INPUT_PULLUP);
  ring.begin();
  ring.setBrightness(120);
  ring.show();
  Serial.println("NeoPixel ring demo - button changes mode, pot changes speed");
  printMode();
}

void loop() {
  int b = digitalRead(BTN_PIN);
  if (b == LOW && lastBtn == HIGH) {
    mode = (mode + 1) % 4;
    printMode();
  }
  lastBtn = b;

  int pot = analogRead(POT_PIN);                 // 0..4095
  int frameDelay = map(pot, 0, 4095, 15, 120);   // fast .. slow

  if (millis() - lastFrame >= frameDelay) {
    lastFrame = millis();
    step = step + 1;
    drawFrame();
  }
  delay(5);
}

Built with FluxBench.AI — the AI workbench for embedded projects.