// https://www.reddit.com/r/FastLED/comments/1c9vdmo/how_would_i_best_program_a_slow_colour_fadeblur/
#include <FastLED.h>
// declare 3 strips with lengths of 12, 50 and 12 pixels
CRGBArray < 12 + 50 + 12 > leds;
CRGBSet const strips[] = {
leds(0, 11),
leds(12, 61),
leds(62, 73),
};
CRGB const colourA = CRGB(255, 0, 0);
CRGB const colourB = CRGB(255, 0, 255);
void setup() {
FastLED.addLeds<WS2812B, PB1, GRB>(leds, leds.len);
}
void loop() {
// smaller numbers give wider gradients
uint16_t const gradientslope = 3000;
// how quickly the gradient moves along the strip, in 1/256ths of a pixel per frame
uint16_t const gradientspeed = 50;
// position of gradient at power up
static int32_t gradientval = 0;
// if the fade hasn't yet completed on the last LED
if ( colourB != *(strips[1].end_pos - 1) ) {
// accumulate the gradient along the strip of LEDs
int32_t ledval = gradientval;
for ( CRGBSet::iterator pixel = strips[1].begin(), end = strips[1].end(); pixel != end; ++pixel ) {
// clamp the fade to the range 0-255
uint8_t fade = 0;
if ( 0 < ledval ) {
fade = 65536 > ledval ? ledval / 256 : 255;
}
// set this LED to the fade level for this point on the gradient
*pixel = blend(colourA, colourB, fade);
// move to next position in the gradient
ledval -= gradientslope;
}
// set the first and last strips to the colours at the ends of the middle strip
fill_solid(strips[0], strips[0].size(), *(strips[1].leds));
fill_solid(strips[2], strips[2].size(), *(strips[1].end_pos - 1));
FastLED.show();
// move the gradient by some amount
gradientval += gradientspeed;
} else {
// the fade has completed
FastLED.delay(1000);
}
}
FPS: 0
Power: 0.00W
Power: 0.00W