#include <Adafruit_NeoPixel.h>
#define PIN 1 // Data pin connected to the NeoPixel strip
#define NUMPIXELS 16 // Number of pixels in the strip
#define DELAY 50 // Delay between color updates (in milliseconds)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
colorCycle(DELAY); // Call the colorCycle function with the specified delay
}
void colorCycle(int delayTime) {
// Define an array of colors to cycle through
uint32_t colors[] = {strip.Color(255, 0, 0), // Red
strip.Color(0, 255, 0), // Green
strip.Color(0, 0, 255)}; // Blue
int numColors = sizeof(colors) / sizeof(colors[0]); // Calculate the number of colors in the array
// Loop through each pair of colors and blend between them
for (int i = 0; i < numColors; i++) {
uint32_t color1 = colors[i];
uint32_t color2 = colors[(i + 1) % numColors]; // Wrap around to the beginning of the array
// Blend between color1 and color2
for (float t = 0.0; t < 1.0; t += 0.01) {
uint8_t red = (1.0 - t) * ((color1 >> 16) & 0xFF) + t * ((color2 >> 16) & 0xFF);
uint8_t green = (1.0 - t) * ((color1 >> 8) & 0xFF) + t * ((color2 >> 8) & 0xFF);
uint8_t blue = (1.0 - t) * (color1 & 0xFF) + t * (color2 & 0xFF);
// Create a blended color and set all pixels to this color
uint32_t blendedColor = strip.Color(red, green, blue);
for (int j = 0; j < strip.numPixels(); j++) {
strip.setPixelColor(j, blendedColor);
}
strip.show(); // Update the NeoPixel strip with the new color
delay(delayTime); // Delay before updating to the next color
}
}
}