#include <FastLED.h>
#define LED_TYPE WS2812B
#define LED_PIN 3
#define NUM_LEDS 256
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS];
//////////////////////////////////////////////////////////////
// 16×16 serpentine matrix mapping
//////////////////////////////////////////////////////////////
int XY(int x, int y) {
int index;
if (y % 2 == 0) {
index = (y * 16) + x;
} else {
index = (y * 16) + (15 - x);
}
return index;
}
//////////////////////////////////////////////////////////////
// EFFECT COUNTER
//////////////////////////////////////////////////////////////
uint8_t currentEffect = 0;
unsigned long lastChange = 0;
const unsigned long EFFECT_TIME = 12000; // 12 sec
//////////////////////////////////////////////////////////////
// EFFECT 1 — Wave from your original code
//////////////////////////////////////////////////////////////
void wave() {
static uint8_t hue = 0;
for (uint8_t y = 0; y < 16; y++) {
for (uint8_t x = 0; x < 16; x++) {
float distance = sqrt(pow(x - 7.5, 2) + pow(y - 7.5, 2));
float angle = atan2(y - 7.5, x - 7.5);
float wave = sin(distance * 0.3 + millis() / 200.0 - angle * 5.0);
uint8_t index = XY(x, y);
leds[index] = CHSV(hue + wave * 20.0, 255, 255);
}
}
hue += 1;
}
//////////////////////////////////////////////////////////////
// EFFECT 2 — simple rainbow
//////////////////////////////////////////////////////////////
void rainbowSimple() {
uint8_t t = millis() / 10;
for (int i = 0; i < NUM_LEDS; i++)
leds[i] = CHSV(t + i, 255, 255);
}
//////////////////////////////////////////////////////////////
// EFFECT 3 — rainbow vertical
//////////////////////////////////////////////////////////////
void rainbowVertical() {
uint8_t t = millis() / 10;
for (int y = 0; y < 16; y++)
for (int x = 0; x < 16; x++)
leds[XY(x,y)] = CHSV(t + y * 10, 255, 255);
}
//////////////////////////////////////////////////////////////
// EFFECT 4 — rainbow horizontal
//////////////////////////////////////////////////////////////
void rainbowHorizontal() {
uint8_t t = millis() / 10;
for (int y = 0; y < 16; y++)
for (int x = 0; x < 16; x++)
leds[XY(x,y)] = CHSV(t + x * 10, 255, 255);
}
//////////////////////////////////////////////////////////////
// EFFECT 5 — color swirl
//////////////////////////////////////////////////////////////
void swirl() {
uint16_t t = millis()/8;
for(int y=0;y<16;y++){
for(int x=0;x<16;x++){
float a = atan2(y-7.5, x-7.5);
float d = sqrt((x-7.5)*(x-7.5)+(y-7.5)*(y-7.5));
leds[XY(x,y)] = CHSV((uint8_t)(t + a*80), 255, sin8(d*20 + t));
}
}
}
//////////////////////////////////////////////////////////////
// EFFECT 6 — zoom radial
//////////////////////////////////////////////////////////////
void zoom() {
uint16_t t = millis()/4;
for(int y=0;y<16;y++){
for(int x=0;x<16;x++){
float d = sqrt(pow(x-7.5,2)+pow(y-7.5,2));
leds[XY(x,y)] = CHSV((uint8_t)(d*20 + t),255,255);
}
}
}
//////////////////////////////////////////////////////////////
// EFFECT 7 — spiral rainbow
//////////////////////////////////////////////////////////////
void spiral() {
uint16_t t = millis()/10;
for(int y=0;y<16;y++){
for(int x=0;x<16;x++){
float a = atan2(y-7.5, x-7.5);
float d = sqrt(pow(x-7.5,2)+pow(y-7.5,2));
leds[XY(x,y)] = CHSV((uint8_t)(a*100 + t),255,255);
}
}
}
//////////////////////////////////////////////////////////////
// EFFECT 8 — diagonal wave
//////////////////////////////////////////////////////////////
void diagWave() {
uint16_t t = millis()/10;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++)
leds[XY(x,y)] = CHSV((uint8_t)(t + (x+y)*6),255,255);
}
//////////////////////////////////////////////////////////////
// EFFECT 9 — sin plasma
//////////////////////////////////////////////////////////////
void sinPlasma() {
uint16_t t = millis()/7;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++) {
uint8_t c = sin8(x*16 + t) + sin8(y*16 - t);
leds[XY(x,y)] = CHSV(c,255,255);
}
}
//////////////////////////////////////////////////////////////
// EFFECT 10 — sun rays
//////////////////////////////////////////////////////////////
void sunRays() {
uint16_t t = millis()/5;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++) {
float a = atan2(y-7.5, x-7.5);
leds[XY(x,y)] = CHSV((uint8_t)(a*120 + t),255,255);
}
}
//////////////////////////////////////////////////////////////
// EFFECT 11 — Noise Plasma
//////////////////////////////////////////////////////////////
void noisePlasma() {
static uint16_t t = 0;
t += 1;
for (uint8_t y=0; y<16; y++)
for (uint8_t x=0; x<16; x++)
leds[XY(x,y)] = CHSV(inoise8(x*20, y*20, t),255,255);
}
//////////////////////////////////////////////////////////////
// EFFECT 12 — Horizontal Sine
//////////////////////////////////////////////////////////////
void sineHorizontal() {
uint16_t t = millis()/6;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++)
leds[XY(x,y)] = CHSV(sin8(x*10 + t) + y*8,255,255);
}
//////////////////////////////////////////////////////////////
// EFFECT 13 — Vertical Sine
//////////////////////////////////////////////////////////////
void sineVertical() {
uint16_t t = millis()/6;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++)
leds[XY(x,y)] = CHSV(sin8(y*10 + t) + x*8,255,255);
}
//////////////////////////////////////////////////////////////
// EFFECT 14 — diamond pulse
//////////////////////////////////////////////////////////////
void diamondPulse() {
float t = millis()/300.0;
for(int y=0;y<16;y++){
for(int x=0;x<16;x++){
float d = abs(x-7.5)+abs(y-7.5);
leds[XY(x,y)] = CHSV((uint8_t)(sin(d*0.6+t)*80+120),255,255);
}
}
}
//////////////////////////////////////////////////////////////
// EFFECT 15 — tunnel
//////////////////////////////////////////////////////////////
void tunnel() {
float t = millis()/200.0;
for(int y=0;y<16;y++){
for(int x=0;x<16;x++){
float dx=x-7.5, dy=y-7.5;
float a=atan2(dy,dx);
float d=sqrt(dx*dx+dy*dy);
leds[XY(x,y)] = CHSV((uint8_t)(a*40+t*30),255, sin8(d*20 - t*40));
}
}
}
//////////////////////////////////////////////////////////////
// EFFECT 16 — expanding rings
//////////////////////////////////////////////////////////////
void rings() {
float t = millis()/200.0;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++){
float d=sqrt(pow(x-7.5,2)+pow(y-7.5,2));
leds[XY(x,y)] = CHSV((uint8_t)(t*40),255,sin8(d*30 + t*50));
}
}
//////////////////////////////////////////////////////////////
// EFFECT 17 — checker rainbow
//////////////////////////////////////////////////////////////
void rainbowChecker() {
uint8_t t=millis()/8;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++)
leds[XY(x,y)] = CHSV(t + (((x&1)^(y&1))?255:0),255,255);
}
//////////////////////////////////////////////////////////////
// EFFECT 18 — Kaleidoscope
//////////////////////////////////////////////////////////////
void kaleido() {
uint16_t t=millis()/3;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++)
leds[XY(x,y)] = CHSV(sin8((x*20 ^ y*20)+t),255,255);
}
//////////////////////////////////////////////////////////////
// EFFECT 19 — Color Melt
//////////////////////////////////////////////////////////////
void colorMelt() {
uint16_t t = millis()/20;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++)
leds[XY(x,y)] = CHSV((x*16+y*8+t)&255,255,255);
}
//////////////////////////////////////////////////////////////
// EFFECT 20 — Meteor
//////////////////////////////////////////////////////////////
void meteor() {
fadeToBlackBy(leds,NUM_LEDS,30);
uint16_t pos = (millis()/10)%NUM_LEDS;
leds[pos] = CHSV(0,0,255);
}
//////////////////////////////////////////////////////////////
// EFFECT 21 — Twisted Waves
//////////////////////////////////////////////////////////////
void twistedWaves() {
float t=millis()/150.0;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++){
float v = sin((x+y)*0.4+t)+sin((x-y)*0.3-t);
leds[XY(x,y)] = CHSV((uint8_t)(v*80+160),255,255);
}
}
//////////////////////////////////////////////////////////////
// EFFECT 22 — Fireworks
//////////////////////////////////////////////////////////////
void fireworks() {
fadeToBlackBy(leds,NUM_LEDS,20);
for(int i=0;i<4;i++){
int px=random8(16);
int py=random8(16);
leds[XY(px,py)] = CHSV(random8(),255,255);
}
}
//////////////////////////////////////////////////////////////
// EFFECT 23 — Lumen Rings
//////////////////////////////////////////////////////////////
void lumen() {
float t=millis()/400.0;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++){
float d=sqrt(pow(x-7.5,2)+pow(y-7.5,2));
leds[XY(x,y)] = CHSV((uint8_t)(150+d*10+t*40),255,sin8(d*25+t*60));
}
}
//////////////////////////////////////////////////////////////
// EFFECT 24 — white twinkles
//////////////////////////////////////////////////////////////
void whiteTwinkles() {
fadeToBlackBy(leds,NUM_LEDS,25);
leds[random16(NUM_LEDS)] = CRGB::White;
}
//////////////////////////////////////////////////////////////
// EFFECT 25 — FIXED explosion
//////////////////////////////////////////////////////////////
void explosion() {
static uint16_t t=0;
t++;
for(int y=0;y<16;y++){
for(int x=0;x<16;x++){
float d = sqrt(pow(x-7.5,2)+pow(y-7.5,2));
uint8_t hue = (uint8_t)(t + d*20);
leds[XY(x,y)] = CHSV(
hue,
255,
sin8(t*4 - d*30)
);
}
}
}
//////////////////////////////////////////////////////////////
// EFFECT 26 — Lava Noise
//////////////////////////////////////////////////////////////
void lava() {
uint16_t t = millis()/4;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++){
uint8_t n=inoise8(x*30,y*20,t);
leds[XY(x,y)] = CHSV(10+n/4,255,n);
}
}
//////////////////////////////////////////////////////////////
// EFFECT 27 — Ocean Noise
//////////////////////////////////////////////////////////////
void ocean() {
uint16_t t=millis()/6;
for(int y=0;y<16;y++)
for(int x=0;x<16;x++){
uint8_t n=inoise8(x*25+10000, y*25+5000, t);
leds[XY(x,y)] = CHSV(140+n/3,255,n);
}
}
//////////////////////////////////////////////////////////////
// EFFECT 28 — Electric Storm
//////////////////////////////////////////////////////////////
void storm() {
fadeToBlackBy(leds,NUM_LEDS,40);
if(random8()<10)
leds[random16(NUM_LEDS)] = CHSV(180,0,255);
}
//////////////////////////////////////////////////////////////
// EFFECT 29 — random flash
//////////////////////////////////////////////////////////////
void randomFlash() {
for(int i=0;i<NUM_LEDS;i++)
leds[i] = CHSV(random8(),255,random8(50,255));
}
//////////////////////////////////////////////////////////////
// EFFECT 30 — confetti
//////////////////////////////////////////////////////////////
void confetti() {
fadeToBlackBy(leds,NUM_LEDS,20);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV(random8(),200,255);
}
//////////////////////////////////////////////////////////////
// EFFECT 31 — pulse wave
//////////////////////////////////////////////////////////////
void pulseWave() {
float t=millis()/500.0;
uint8_t v = (sin(t)+1)*127;
fill_solid(leds,NUM_LEDS,CHSV(v,255,255));
}
//////////////////////////////////////////////////////////////
// SELECT EFFECT
//////////////////////////////////////////////////////////////
void showEffect(uint8_t id) {
switch(id) {
case 0: wave(); break;
case 1: rainbowSimple(); break;
case 2: rainbowVertical(); break;
case 3: rainbowHorizontal(); break;
case 4: swirl(); break;
case 5: zoom(); break;
case 6: spiral(); break;
case 7: diagWave(); break;
case 8: sinPlasma(); break;
case 9: sunRays(); break;
case 10: noisePlasma(); break;
case 11: sineHorizontal(); break;
case 12: sineVertical(); break;
case 13: diamondPulse(); break;
case 14: tunnel(); break;
case 15: rings(); break;
case 16: rainbowChecker(); break;
case 17: kaleido(); break;
case 18: colorMelt(); break;
case 19: meteor(); break;
case 20: twistedWaves(); break;
case 21: fireworks(); break;
case 22: lumen(); break;
case 23: whiteTwinkles(); break;
case 24: explosion(); break;
case 25: lava(); break;
case 26: ocean(); break;
case 27: storm(); break;
case 28: randomFlash(); break;
case 29: confetti(); break;
case 30: pulseWave(); break;
}
}
//////////////////////////////////////////////////////////////
// SETUP
//////////////////////////////////////////////////////////////
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
}
//////////////////////////////////////////////////////////////
// MAIN LOOP
//////////////////////////////////////////////////////////////
void loop() {
if (millis() - lastChange > EFFECT_TIME) {
lastChange = millis();
currentEffect = (currentEffect + 1) % 31; // total 31 effects
}
showEffect(currentEffect);
FastLED.show();
}
FPS: 0
Power: 0.00W
Power: 0.00W