// https://forum.arduino.cc/t/easiest-way-to-slowly-ramp-led-strip/1329379/161
#include <FastLED.h> https://github.com/FastLED/FastLED
#define NUMPIX 50
#define DATAPIN 5
#define MAXBRIGHT 255
CRGB led[NUMPIX]; // FastLED object
int r, g, b; // color values
#define DELAY 25 // about 25 seconds. larger number for slower transition
void setup() {
FastLED.addLeds<WS2812B, DATAPIN, GRB>(led, NUMPIX);
FastLED.setBrightness(MAXBRIGHT);
FastLED.clear();
FastLED.show();
Serial.begin(115200);
}
void loop() {
sunrisesunset();
// christmas();
// initialsequence();
}
// Colors use RGB values. First three RGB "from color", last three RGB "to color"
void christmas() {
fade_from_to( 0, 0, 0, 0, 255, 0); // blk grn
fade_from_to( 0, 255, 0, 0, 0, 0); // grn blk
fade_from_to( 0, 0, 0, 255, 0, 0); // blk red
fade_from_to(255, 0, 0, 0, 0, 0); // red blk
}
void sunrisesunset() {
fade_from_to( 0, 0, 0, 0, 0, 255); // blk blu
fade_from_to( 0, 0, 255, 255, 255, 255); // blu wht
fade_from_to(255, 255, 255, 255, 165, 0); // wht org
fade_from_to(255, 165, 0, 160, 32, 240); // org pur
fade_from_to(160, 32, 240, 255, 192, 208); // pur pnk
fade_from_to(255, 192, 208, 0, 0, 255); // pnk blu
fade_from_to( 0, 0, 255, 0, 0, 0); // blu blk
}
void initialsequence() {
fade_from_to( 0, 0, 0, 255, 255, 0); // blk yel
fade_from_to(255, 255, 0, 255, 165, 0); // yel org
fade_from_to(255, 165, 0, 160, 32, 240); // org pur
fade_from_to(160, 32, 240, 0, 0, 0); // pur blk
}
void fade_from_to(int r0, int g0, int b0, int r1, int g1, int b1) {
int red, grn, blu; // colors
int rs = getsign(r0, r1); // will it fade up or down
int gs = getsign(g0, g1);
int bs = getsign(b0, b1);
for (int i = 0; i < 256; i++) { // count 0 to 255
for (int j = 0; j < NUMPIX; j++) { // load neopixel buffers
// color = start color value + direction * proportional step (difference / steps)
red = r0 + (rs * i) * (abs(r0 - r1) / 255.0); // result is type "float" due to 255.0
grn = g0 + (gs * i) * (abs(g0 - g1) / 255.0);
blu = b0 + (bs * i) * (abs(b0 - b1) / 255.0);
led[j] = CRGB(red, grn, blu);
}
delay(DELAY); // fade speed, larger value for slower fade
FastLED.show(); // display neopixel buffer
// debugValues(i, red, grn, blu); // print color values (see function for explanation)
}
}
int getsign (int color0, int color1) { // +/- sign for calculating fade up or down
int colorSign;
if (color0 > color1) // starting color is greater than ending color
colorSign = -1; // fading direction is negative
else if (color0 < color1) // starting color is less than ending color
colorSign = 1; // fading direction is positive
else // starting color is equal to ending color
colorSign = 0; // remove fade by multiplying by zero
return (colorSign);
}
void debugValues(int i, int r, int g, int b) {
// verify index [i] matches starting color values
// verify no r, g, b, values < 0 or > 255
// verify index [i] matches ending color values
Serial.print(i); // index
Serial.print(" ");
Serial.print(r); // red
Serial.print(" ");
Serial.print(g); // green
Serial.print(" ");
Serial.print(b); // blue
Serial.println();
}
1000 uF
E-cap