#include <Adafruit_NeoPixel.h>
#define PIN 6 // Define the pin where your LED strip is connected
#define NUM_LEDS 32 // Define the number of LEDs in your strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
//rainbowCycle(20); // Call rainbow cycle effect
theaterChase(strip.Color(127, 127, 127), 50); // Call theater chase effect
colorWipe(strip.Color(0, 255, 0), 50); // Call color wipe effect
blink(strip.Color(255, 0, 0), 500); // Call blink effect
sparkle(strip.Color(255, 255, 255), 50); // Call sparkle effect
fade(strip.Color(0, 0, 255), 10); // Call fade effect
meteorRain(strip.Color(255, 255, 255), 10, 64, true, 30); // Call meteor rain effect
twinkle(strip.Color(255, 255, 0), 20); // Call twinkle effect
}
void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
delay(wait);
}
}
void theaterChase(uint32_t color, int wait) {
for (int j=0; j<10; j++) { // Do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, color); // Turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); // Turn every third pixel off
}
}
}
}
void rainbowCycle(int wait) {
for (int j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for (int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
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);
}
void blink(uint32_t color, int wait) {
for(int i=0; i<3; i++) { // Blink the LED 3 times
for(int j=0; j<strip.numPixels(); j++) {
strip.setPixelColor(j, color); // Turn all LEDs to the specified color
}
strip.show();
delay(wait);
for(int j=0; j<strip.numPixels(); j++) {
strip.setPixelColor(j, 0); // Turn all LEDs off
}
strip.show();
delay(wait);
}
}
void sparkle(uint32_t color, int wait) {
int pixel = random(strip.numPixels());
strip.setPixelColor(pixel, color);
strip.show();
delay(wait);
strip.setPixelColor(pixel, 0);
}
void fade(uint32_t color, int wait) {
for(int brightness = 0; brightness < 256; brightness++) {
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color((color >> 16) * brightness / 255, (color >> 8 & 0xFF) * brightness / 255, (color & 0xFF) * brightness / 255));
}
strip.show();
delay(wait);
}
for(int brightness = 255; brightness >= 0; brightness--) {
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color((color >> 16) * brightness / 255, (color >> 8 & 0xFF) * brightness / 255, (color & 0xFF) * brightness / 255));
}
strip.show();
delay(wait);
}
}
void meteorRain(uint32_t color, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int wait) {
strip.clear();
for(int i = 0; i < strip.numPixels()+strip.numPixels(); i++) {
for(int j=0; j < strip.numPixels(); j++) {
if((!meteorRandomDecay) || (random(10) > 5)) {
fadeToBlack(j, meteorTrailDecay);
}
}
for(int j = 0; j < meteorSize; j++) {
if(( i-j <strip.numPixels()) && (i-j >= 0)) {
strip.setPixelColor(i-j, color);
}
}
strip.show();
delay(wait);
}
}
void fadeToBlack(int ledNo, byte fadeValue) {
uint32_t oldColor;
uint8_t r, g, b;
oldColor = strip.getPixelColor(ledNo);
r = (oldColor >> 16) & 0xFF;
g = (oldColor >> 8) & 0xFF;
b = oldColor & 0xFF;
r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
strip.setPixelColor(ledNo, r,g,b);
}
void twinkle(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, (random(10) > 5) ? color : 0);
}
strip.show();
delay(wait);
strip.clear();
strip.show();
}