// https://www.reddit.com/r/FastLED/comments/16k4st2/transition_from_one_colour_to_another_using_for/
#include <FastLED.h>
#define NUM_LEDS 24
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, PB1, GRB>(leds, NUM_LEDS);
}
void loop() {
CRGB colA = 0xffd500;
CRGB colB = 0x00bf60;
for (int i = 0; i < 256; i++) {
CRGB col = colA;
fadeTowardColor(col, colB, i);
fill_solid(leds, NUM_LEDS, col);
FastLED.show();
delay(10);
}
}
// The code below is from Mark Kriegsman's examples
// https://gist.github.com/kriegsman/d0a5ed3c8f38c64adcb4837dafb6e690
// Helper function that blends one uint8_t toward another by a given amount
void nblendU8TowardU8( uint8_t& cur, const uint8_t target, uint8_t amount) {
if( cur == target) return;
if( cur < target ) {
uint8_t delta = target - cur;
delta = scale8_video( delta, amount);
cur += delta;
} else {
uint8_t delta = cur - target;
delta = scale8_video( delta, amount);
cur -= delta;
}
}
// Blend one CRGB color toward another CRGB color by a given amount.
// Blending is linear, and done in the RGB color space.
// This function modifies 'cur' in place.
CRGB fadeTowardColor( CRGB& cur, const CRGB& target, uint8_t amount) {
nblendU8TowardU8( cur.red, target.red, amount);
nblendU8TowardU8( cur.green, target.green, amount);
nblendU8TowardU8( cur.blue, target.blue, amount);
return cur;
}