/**
* Smoothly fades the onboard NeoPixel through the full HSV color wheel.
* Works on the Adafruit ESP32-S3 Feather (and in Wokwi with the DevKitC).
*
* Requires the Adafruit NeoPixel library:
* Sketch -> Include Library -> Manage Libraries -> search "Adafruit NeoPixel"
*
* See: https://makeabilitylab.github.io/physcomp/esp32/led-fade
*/
#include <Adafruit_NeoPixel.h>
// On the Wokwi generic ESP32-S3 DevKit, the NeoPixel is on GPIO 38
const int WOKWI_NEOPIXEL_PIN = 38;
// Initialize the NeoPixel object
Adafruit_NeoPixel _pixel(1, WOKWI_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
const int HUE_STEP = 256; // How much to advance the hue each frame
const uint32_t MAX_HUE = 65536; // Full color wheel (360°) in 16-bit hue
const int DELAY_MS = 20; // ~50 fps for smooth animation
uint32_t _hue = 0; // Current position on the color wheel
void setup() {
// The NeoPixel on the ESP32-S3 Feather has a separate power pin
// that must be set HIGH before the NeoPixel will light up
#if defined(NEOPIXEL_POWER)
pinMode(NEOPIXEL_POWER, OUTPUT);
digitalWrite(NEOPIXEL_POWER, HIGH);
#endif
_pixel.begin();
_pixel.setBrightness(30); // 0-255; keep it low to avoid blinding yourself!
_pixel.show();
}
void loop() {
// ColorHSV takes: hue (0-65535), saturation (0-255), value/brightness (0-255)
// gamma32 applies perceptual brightness correction for smoother color transitions
uint32_t color = _pixel.gamma32(_pixel.ColorHSV(_hue, 255, 255));
_pixel.setPixelColor(0, color);
_pixel.show();
// Advance the hue and wrap around at 65536 (back to red)
_hue = (_hue + HUE_STEP) % MAX_HUE;
delay(DELAY_MS);
}