// One WS2812
#include <FastLED.h> // https://github.com/FastLED/FastLED
#define led 1 // number of WS2812
#define pin 6 // data pin
CRGB leds[led]; // FastLED object (leds[])
int state = 0, states = 6; // color states
int minimum = 0, maximum = 255, increas, decreas, direct; // counters - misspelled to format words
unsigned long loopTimer, crossFadeRGBTimer;
int i, count, funCount = 6; // function count
void setup() {
// Serial.begin(115200);
// pinMode(LED_BUILTIN, OUTPUT);
FastLED.addLeds<WS2812, pin, GRB>(leds, led);
FastLED.clear();
FastLED.setBrightness(maximum);
FastLED.show();
}
void loop() {
// unsigned long loopTimeout = 1000 * 60 * 10; // 1000ms * 60s/m * 10min
unsigned long loopTimeout = 1000 * 5; // 1000ms * 5 seconds for testing
switch (count) {
case 0: wigwag(0, 0, 255, 255, 255, 255); break; // blu wht
case 1: updown(); break;
case 2: wigwag(255, 0, 0, 0, 255, 0); break; // red grn
case 3: ramp(); break;
case 4: crossFadeRGB(); break;
case 5: blinkblonk(); break;
case 6: flicker(); break;
default: break;
}
if (millis() - loopTimer > loopTimeout) {
loopTimer = millis();
if (count++ == funCount)
count = 0;
FastLED.clear();
FastLED.show();
}
}
void flicker() {
leds[0] = CRGB::Red;
FastLED.show();
delay(50);
leds[0] = CRGB::Green;
FastLED.show();
delay(75);
}
void blinkblonk() {
if (i)
leds[0] = CRGB(0, 0, 255);
else
leds[0] = CRGB(255, 255, 255);
FastLED.show();
delay(500);
leds[0] = CRGB(0, 0, 0);
FastLED.show();
delay(500);
i = !i;
}
void wigwag(int r1, int g1, int b1, int r2, int g2, int b2) {
int myDelay = 1000;
if (state) {
leds[0] = CRGB(r1, g1, b1);
FastLED.show();
delay(50);
leds[0] = CRGB(r2, g2, b2);
FastLED.show();
delay(50);
leds[0] = CRGB(r1, g1, b1);
FastLED.show();
delay(500);
} else {
leds[0] = CRGB(r2, g2, b2);
FastLED.show();
delay(50);
leds[0] = CRGB(r1, g1, b1);
FastLED.show();
delay(50);
leds[0] = CRGB(r2, g2, b2);
FastLED.show();
delay(500);
}
state = !state;
delay(myDelay);
}
void crossFadeRGB() {
unsigned long timeoutcrossFadeRGB = 3900; // micros
if (micros() - crossFadeRGBTimer > timeoutcrossFadeRGB) {
crossFadeRGBTimer = micros();
if (increas++ == maximum) { // increment step until counter is max
increas = minimum; // reset step counter
if (state++ == states) // increment state until state is max
state = 1; // reset state
}
decreas = maximum - increas; // invert counter to decrease values
switch (state) { // blend colors one bit per step // 256 red * 256 grn * 256 blu = 16,777,216 colors)
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();
}
}
void ramp() {
int myDelay = 10; // 10ms = 4sec
for (int j = 0; j < 2; j++) {
for (int i = 0; i < 256; i++) {
if (j)
leds[0] = CRGB(i, i, i); // white
else
leds[0] = CRGB(0, 0, i); // blue
FastLED.show();
delay(myDelay);
}
}
}
void updown() {
int myDelay = 10; // 10ms = 10sec
for (int j = 0; j < 2; j++) {
for (int i = 0; i < 256; i++) {
if (j)
leds[0] = CRGB(i, i, i); // white
else
leds[0] = CRGB(0, 0, i); // blue
FastLED.show();
delay(myDelay);
}
for (int i = 0; i < 256; i++) {
if (j)
leds[0] = CRGB(255 - i, 255 - i, 255 - i); // white
else
leds[0] = CRGB(0, 0, 255 - i); // blue
FastLED.show();
}
delay(myDelay);
}
}