#include <Adafruit_NeoPixel.h>
#define LED_PIN 16 // ESP32 GPIO 16 (TX2)
#define LED_COUNT 270 // 9 strips × 30 LEDs = 270 total
#define LEDS_PER_STRIP 30
#define NUM_STRIPS 9
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
Serial.println("ESP32 WS2812B - 9 Strip Demo");
strip.begin();
strip.setBrightness(20); // Keep brightness low for Wokwi
strip.show();
}
void loop() {
// Demo 1: Rainbow across all strips
Serial.println("Rainbow effect...");
rainbow(10);
delay(2000);
// Demo 2: Strip-by-strip different colors
Serial.println("Strip-by-strip colors...");
stripByStripColors();
delay(3000);
// Demo 3: Wave across strips
Serial.println("Wave effect...");
for(int i = 0; i < 3; i++) {
waveAcrossStrips(strip.Color(0, 100, 255), 150);
}
delay(2000);
// Demo 4: Theater chase
Serial.println("Theater chase...");
theaterChase(strip.Color(255, 255, 255), 100);
delay(2000);
}
void rainbow(int wait) {
for(long firstPixelHue = 0; firstPixelHue < 65536; firstPixelHue += 512) {
strip.rainbow(firstPixelHue);
strip.show();
delay(wait);
}
}
void stripByStripColors() {
for(int stripNum = 0; stripNum < NUM_STRIPS; stripNum++) {
uint32_t color;
switch(stripNum) {
case 0: color = strip.Color(255, 0, 0); break; // Red
case 1: color = strip.Color(255, 127, 0); break; // Orange
case 2: color = strip.Color(255, 255, 0); break; // Yellow
case 3: color = strip.Color(0, 255, 0); break; // Green
case 4: color = strip.Color(0, 255, 255); break; // Cyan
case 5: color = strip.Color(0, 0, 255); break; // Blue
case 6: color = strip.Color(75, 0, 130); break; // Indigo
case 7: color = strip.Color(148, 0, 211); break; // Violet
case 8: color = strip.Color(255, 255, 255); break;// White
}
fillStrip(stripNum, color);
}
strip.show();
}
void fillStrip(int stripNum, uint32_t color) {
int startLED = stripNum * LEDS_PER_STRIP;
int endLED = startLED + LEDS_PER_STRIP;
for(int i = startLED; i < endLED; i++) {
strip.setPixelColor(i, color);
}
}
void waveAcrossStrips(uint32_t color, int wait) {
for(int stripNum = 0; stripNum < NUM_STRIPS; stripNum++) {
strip.clear();
int startLED = stripNum * LEDS_PER_STRIP;
int endLED = startLED + LEDS_PER_STRIP;
for(int i = startLED; i < endLED; i++) {
strip.setPixelColor(i, color);
}
strip.show();
delay(wait);
}
}
void theaterChase(uint32_t color, int wait) {
for(int a = 0; a < 5; a++) {
for(int b = 0; b < 3; b++) {
strip.clear();
for(int c = b; c < strip.numPixels(); c += 3) {
strip.setPixelColor(c, color);
}
strip.show();
delay(wait);
}
}
}