#include <Adafruit_NeoPixel.h>
#define PIN 5 // GPIO pin connected to the data input of the LED matrix
#define NUMPIXELS 256 // 8 x 32 = 256 LEDs
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
rainbowCycle(20); // Run rainbow cycle animation with 20ms delay per step
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
// Draw rainbow that uniformly distributes across all pixels
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) { // cycle all 256 colors in the wheel
for(i=0; i<strip.numPixels(); i++) {
// Calculate color for each pixel based on position and cycle step
strip.setPixelColor(i, Wheel((i * 256 / strip.numPixels() + j) & 255));
}
strip.show();
delay(wait);
}
}
https://wokwi.com/projects/new/esp32-s3