#include <FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 34
#define BRIGHTNESS 64
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
// Function declarations
void rainbowCycle(int speedDelay);
void colorWipe(CRGB color, int speedDelay);
void theaterChase(CRGB color, int speedDelay);
void blink(CRGB color, int speedDelay);
void runningLights(CRGB color, int waveDelay);
void twinkle(int speedDelay);
void fade(CRGB color, int fadeAmount);
void strobe(CRGB color, int speedDelay);
void wave(CRGB color, int waveDelay);
void sparkle(CRGB color, int speedDelay);
void fire(int cooling, int sparking, int speedDelay);
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
}
void loop() {
rainbowCycle(10);
colorWipe(CRGB::Red, 50);
theaterChase(CRGB::Blue, 50);
blink(CRGB::Green, 500);
runningLights(CRGB::Yellow, 50);
twinkle(100);
fade(CRGB::Purple, 5);
strobe(CRGB::White, 100);
wave(CRGB::Orange, 50);
sparkle(CRGB::Aqua, 100);
fire(55, 120, 15);
}
// Pattern implementations
void rainbowCycle(int speedDelay) {
for(long firstHue = 0; firstHue < 256*5; firstHue += 1) {
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV((firstHue + i * 256 / NUM_LEDS) & 255, 255, 255);
}
FastLED.show();
delay(speedDelay);
}
}
void colorWipe(CRGB color, int speedDelay) {
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = color;
FastLED.show();
delay(speedDelay);
}
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Black;
FastLED.show();
delay(speedDelay);
}
}
void theaterChase(CRGB color, int speedDelay) {
for (int j = 0; j < 10; j++) {
for (int q = 0; q < 3; q++) {
for (int i = 0; i < NUM_LEDS; i = i + 3) {
leds[i+q] = color;
}
FastLED.show();
delay(speedDelay);
for (int i = 0; i < NUM_LEDS; i = i + 3) {
leds[i+q] = CRGB::Black;
}
}
}
}
void blink(CRGB color, int speedDelay) {
fill_solid(leds, NUM_LEDS, color);
FastLED.show();
delay(speedDelay);
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
delay(speedDelay);
}
void runningLights(CRGB color, int waveDelay) {
for (int j = 0; j < NUM_LEDS*2; j++) {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = color * ((sin(i + j) * 127 + 128) / 255.0);
}
FastLED.show();
delay(waveDelay);
}
}
void twinkle(int speedDelay) {
fill_solid(leds, NUM_LEDS, CRGB::Black);
for (int i = 0; i < 8; i++) {
leds[random(NUM_LEDS)] = CRGB::White;
FastLED.show();
delay(speedDelay);
fill_solid(leds, NUM_LEDS, CRGB::Black);
}
}
void fade(CRGB color, int fadeAmount) {
fill_solid(leds, NUM_LEDS, color);
FastLED.show();
for (int i = 0; i < 255; i++) {
fill_solid(leds, NUM_LEDS, color.nscale8_video(255 - i));
FastLED.show();
delay(fadeAmount);
}
for (int i = 255; i >= 0; i--) {
fill_solid(leds, NUM_LEDS, color.nscale8_video(255 - i));
FastLED.show();
delay(fadeAmount);
}
}
void strobe(CRGB color, int speedDelay) {
fill_solid(leds, NUM_LEDS, color);
FastLED.show();
delay(speedDelay);
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
delay(speedDelay);
}
void wave(CRGB color, int waveDelay) {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = color * (sin(i) * 127 + 128) / 255.0;
}
FastLED.show();
delay(waveDelay);
}
void sparkle(CRGB color, int speedDelay) {
int pos = random(NUM_LEDS);
leds[pos] = color;
FastLED.show();
delay(speedDelay);
leds[pos] = CRGB::Black;
FastLED.show();
delay(speedDelay);
}
void fire(int cooling, int sparking, int speedDelay) {
static byte heat[NUM_LEDS];
for (int i = 0; i < NUM_LEDS; i++) {
heat[i] = qsub8(heat[i], random(0, ((cooling * 10) / NUM_LEDS) + 2));
}
for (int k = NUM_LEDS - 1; k >= 2; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
}
if (random(255) < sparking) {
int y = random(7);
heat[y] = qadd8(heat[y], random(160, 255));
}
for (int j = 0; j < NUM_LEDS; j++) {
CRGB color = HeatColor(heat[j]);
int pixelnumber = (NUM_LEDS - 1) - j;
leds[pixelnumber] = color;
}
FastLED.show();
delay(speedDelay);
}