Dynamic Color Shifting with NeoPixels
subratasarkar20
c_cpp
19 days ago
1.0 kB
2
Indexable
Never
#include <Adafruit_NeoPixel.h> #define NUMPIXELS 32 #define PIN 13 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); int offset = 0; // Variable to keep track of the shifting void setup() { pixels.begin(); } void loop() { for (int i = 0; i < NUMPIXELS; i++) { // Shift starting color by 'offset' int colorIndex = (i + offset) % 5; uint32_t color; switch (colorIndex) { case 0: color = pixels.Color(204, 51, 255); break; // COLOR 1 case 1: color = pixels.Color(204, 0, 255); break; // COLOR 2 case 2: color = pixels.Color(102, 0, 255); break; // COLOR 3 case 3: color = pixels.Color(102, 51, 255); break; // COLOR 4 case 4: color = pixels.Color(102, 102, 255); break; // COLOR 5 } pixels.setPixelColor(i, color); } pixels.show(); delay(50); // Update every 50ms // Increment the offset to shift colors in the next loop iteration offset = (offset + 1) % 5; // Keep the offset within 0 to 4 }
Leave a Comment