// One WS2812
#include <FastLED.h> // https://github.com/FastLED/FastLED
#define leds 1 // number of WS2812
#define pin 6 // data pin
CRGB led[leds]; // FastLED object (led[])
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 = 8; // function count
#define BLUWHT 0, 0, 255, 255, 255, 255
#define REDGRN 255, 0, 0, 0, 255, 0
void setup() {
// Serial.begin(115200);
// pinMode(LED_BUILTIN, OUTPUT);
FastLED.addLeds<WS2812, pin, GRB>(led, leds);
FastLED.clear();
FastLED.setBrightness(maximum);
FastLED.show();
}
void loop() {
// unsigned long loopTimeout = 1000 * 60 * 10; // 1000ms * 60s/m * 10min
unsigned long loopTimeout = 1000 * 10; // 1000ms * 5 seconds for testing
switch (count) {
case 0: wigwag(BLUWHT); break; // blu wht
case 1: updown(); break;
case 2: wigwag(REDGRN); break; // red grn
case 3: ramp(); break;
case 4: crossFadeRGB(); break;
case 5: blinkblonk(); break;
case 6: flicker(); break;
case 7: onetwo(); break;
case 8: blend(); break;
default: break;
}
if (millis() - loopTimer > loopTimeout) {
loopTimer = millis();
if (count++ == funCount)
count = 0;
FastLED.clear();
FastLED.show();
}
}
void blend() {
for (int i = 0; i < 256; i++) {
led[0] = CRGB(i, 255 - i, 0);
FastLED.show();
delay(10);
}
for (int i = 0; i < 256; i++) {
led[0] = CRGB(255 - i, i, 0);
FastLED.show();
delay(10);
}
}
void onetwo() {
led[0] = CRGB::White;
FastLED.show();
delay(2000);
led[0] = CRGB::Blue;
FastLED.show();
delay(2000);
}
void flicker() {
led[0] = CRGB::Red;
FastLED.show();
delay(50);
led[0] = CRGB::Green;
FastLED.show();
delay(75);
}
void blinkblonk() {
if (i)
led[0] = CRGB(0, 0, 255);
else
led[0] = CRGB(255, 255, 255);
FastLED.show();
delay(500);
led[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) {
led[0] = CRGB(r1, g1, b1);
FastLED.show();
delay(50);
led[0] = CRGB(r2, g2, b2);
FastLED.show();
delay(50);
led[0] = CRGB(r1, g1, b1);
FastLED.show();
delay(500);
} else {
led[0] = CRGB(r2, g2, b2);
FastLED.show();
delay(50);
led[0] = CRGB(r1, g1, b1);
FastLED.show();
delay(50);
led[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: led[0] = CRGB(increas, minimum, minimum); break; // blk (0,0,0) to red (1,0,0) - blk one time only
case 1: led[0] = CRGB(maximum, increas, minimum); break; // red (1,0,0) to yel (1,1,0)
case 2: led[0] = CRGB(decreas, maximum, minimum); break; // yel (1,1,0) to grn (0,1,0)
case 3: led[0] = CRGB(minimum, maximum, increas); break; // grn (0,1,0) to cyn (0,1,1)
case 4: led[0] = CRGB(minimum, decreas, maximum); break; // cyn (0,1,1) to blu (0,0,1)
case 5: led[0] = CRGB(increas, minimum, maximum); break; // blu (0,0,1) to mag (1,0,1)
case 6: led[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)
led[0] = CRGB(i, i, i); // white
else
led[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)
led[0] = CRGB(i, i, i); // white
else
led[0] = CRGB(0, 0, i); // blue
FastLED.show();
delay(myDelay);
}
for (int i = 0; i < 256; i++) {
if (j)
led[0] = CRGB(255 - i, 255 - i, 255 - i); // white
else
led[0] = CRGB(0, 0, 255 - i); // blue
FastLED.show();
}
delay(myDelay);
}
}