#include <Adafruit_NeoPixel.h>
#define LED_PIN D5
#define LED_COUNT 24
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
int currentScene = 1;
unsigned long lastSwitch = 0;
const unsigned long sceneDuration = 5000;
unsigned long lastUpdate = 0;
void setup() {
strip.begin();
strip.show();
}
void loop() {
if (millis() - lastSwitch > sceneDuration) {
currentScene++;
if (currentScene > 3) currentScene = 1;
strip.clear();
strip.show();
lastSwitch = millis();
}
if (millis() - lastUpdate > 50) {
lastUpdate = millis();
runScene(currentScene);
}
}
void runScene(int id) {
switch (id) {
case 1: fireEffect(); break;
case 2: moonlightPulse(); break;
case 3: morningSunrise(); break;
}
}
// π₯ Fire β flickering reds and oranges
void fireEffect() {
for (int i = 0; i < LED_COUNT; i++) {
int r = random(180, 255);
int g = random(30, 80);
strip.setPixelColor(i, strip.Color(r, g, 0));
}
strip.show();
}
// π Moonlight β gentle pulsing blues and purples
void moonlightPulse() {
static int brightness = 0;
static int fadeAmount = 5;
uint32_t baseColor = strip.Color(80, 0, 160); // moonlight purple-blue
for (int i = 0; i < LED_COUNT; i++) {
strip.setPixelColor(i, strip.Color(
(baseColor >> 16 & 0xFF) * brightness / 255,
(baseColor >> 8 & 0xFF) * brightness / 255,
(baseColor & 0xFF) * brightness / 255));
}
strip.show();
brightness += fadeAmount;
if (brightness <= 0 || brightness >= 255) fadeAmount = -fadeAmount;
}
// π Morning Sun β radiant golden sweep
void morningSunrise() {
static int i = 0;
uint32_t sunColor = strip.Color(255, 180, 50); // golden amber
strip.setPixelColor(i, sunColor);
strip.show();
i = (i + 1) % LED_COUNT;
}
/***********************************How It Works:
β’ Each scene is a separate function (, , )
β’ A timer switches scenes automatically
β’ Animations update every 50ms for smooth motion
π‘ Why Itβs Special:
β’ Visually expressive and easy to understand
β’ Modular and expandable (OLED captions, buttons, etc.)
β’ Perfect for storytelling, student demos, or poetic displays
***********************************************************/
Loading
xiao-esp32-s3
xiao-esp32-s3