// 256 red * 256 grn * 256 blu = 16,777,216 colors)
#include <FastLED.h> // https://github.com/FastLED/FastLED
#define led 1 // number of WS2812
#define pin 2 // WS2812 pin
CRGB leds[led]; // FastLED object (leds[])
int stage = 0, stages = 6; // color stages
int minimum = 0, maximum = 255, increas, decreas; // counters - misspelled to format words
// unsigned long fadeTimer, fadeTimeout = 3900; // microseconds = 3.9 milliseconds
unsigned long fadeTimer, fadeTimeout = 1000; // microseconds = 1 millisecond
void setup() {
FastLED.addLeds<WS2812, pin, GRB>(leds, led);
FastLED.clear();
FastLED.setBrightness(maximum);
FastLED.show();
}
void loop() {
if (micros() - fadeTimer > fadeTimeout) {
fadeTimer = micros();
fade();
}
}
void fade() {
int pause = 50;
if (increas++ == maximum) { // increment step until counter is max
increas = minimum; // reset step counter
if (stage++ == stages) // increment stage until stage is max
stage = 1; // reset stage
}
decreas = maximum - increas; // invert counter to decrease values
switch (stage) { // blend colors one bit per step
case 0: leds[0] = CRGB(increas, minimum, minimum); break; // blk (0,0,0) to red (1,0,0) - blk one time only
case 1: leds[0] = CRGB(maximum, increas, minimum); break; // red (1,0,0) to yel (1,1,0)
case 2: leds[0] = CRGB(decreas, maximum, minimum); break; // yel (1,1,0) to grn (0,1,0)
case 3: leds[0] = CRGB(minimum, maximum, increas); break; // grn (0,1,0) to cyn (0,1,1)
case 4: leds[0] = CRGB(minimum, decreas, maximum); break; // cyn (0,1,1) to blu (0,0,1)
case 5: leds[0] = CRGB(increas, minimum, maximum); break; // blu (0,0,1) to mag (1,0,1)
case 6: leds[0] = CRGB(maximum, minimum, decreas); break; // mag (1,0,1) to red (1,0,0)
default: break;
}
FastLED.show();
}
ElctCap
1000uF