#include <Adafruit_NeoPixel.h>
// Define the GPIO pin connected to the NeoPixel data input
#define PIN 5
// Define the number of pixels in the NeoPixel ring
#define NUMPIXELS 32
// Create an instance of the Adafruit_NeoPixel class
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Initialize the NeoPixel library
pixels.begin();
pixels.show(); // Turn off all pixels initially
}
void loop() {
// Example: Rainbow cycle effect
rainbowCycle(10); // 10ms delay between each color update
}
// Rainbow Cycle Function
void rainbowCycle(uint8_t wait) {
for (int j = 0; j < 256; j++) { // Full cycle of colors
for (int i = 0; i < NUMPIXELS; i++) {
uint16_t colorIndex = (i * 256 / NUMPIXELS + j) & 255;
pixels.setPixelColor(i, Wheel(colorIndex));
}
pixels.show();
delay(wait);
}
}
// Generate a color based on a wheel position (0-255)
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}