#include <Adafruit_NeoPixel.h>
#define PIN 6 // Pin connected to the data input of the first LED
#define NUM_LEDS 30 // Number of RGB LEDs (adjust based on your setup)
#define BRIGHTNESS 50 // Set brightness level (0 to 255)
// Create a NeoPixel object
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin(); // Initialize the LED strip
strip.setBrightness(BRIGHTNESS);
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Example 1: Solid Color
solidColor(strip.Color(255, 0, 0)); // Red
delay(2000);
solidColor(strip.Color(0, 255, 0)); // Green
delay(2000);
solidColor(strip.Color(0, 0, 255)); // Blue
delay(2000);
// Example 2: Color wipe
colorWipe(strip.Color(0, 255, 255), 50); // Cyan color wipe
delay(1000);
// Example 3: Rainbow effect
rainbowCycle(20);
delay(5000);
// Example 4: Theater Chase effect
theaterChase(strip.Color(255, 0, 0), 50); // Red theater chase
delay(1000);
}
// Set all LEDs to the same color
void solidColor(uint32_t color) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, color);
}
strip.show();
}
// Color wipe effect
void colorWipe(uint32_t color, int wait) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, color);
strip.show();
delay(wait);
}
}
// Rainbow effect
void rainbowCycle(int wait) {
for (int j = 0; j < 256; j++) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, Wheel((i + j) & 255));
}
strip.show();
delay(wait);
}
}
// Generate a color from a wheel of 256 colors
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
// Theater chase effect
void theaterChase(uint32_t color, int wait) {
for (int q = 0; q < 10; q++) {
for (int i = 0; i < NUM_LEDS; i = i + 3) {
strip.setPixelColor(i, color);
}
strip.show();
delay(wait);
for (int i = 0; i < NUM_LEDS; i = i + 3) {
strip.setPixelColor(i, 0); // Turn off LEDs
}
strip.show();
delay(wait);
}
}