I don’t know if I should start a new thread or just post it here.
I have a problem which I am afraid I need your help to solve.
If I fade from one color to two colors no problem, but if I fade from 2 colors to 2 different colors the leds flickers. I guess it something to do with the function CRGB fadeTowardColor( CRGB& cur, const CRGB& target, uint8_t amount)
Would you please take a look.
Thank you in advance
void loop() {
if (update1Color == true) {
setBright(brightness);
setAll(colorRed, colorGreen, colorBlue);
}
if (update2Color == true) {
setBright(brightness);
set2Color(colorRed, colorGreen, colorBlue, colorRed2, colorGreen2, colorBlue2);
}
if (updateFadeColors1 == true) {
fadeTo(fadeRed, fadeGreen, fadeBlue, fadeDelay, fadeAmount);
}
if (updateFadeColors2 == true) {
fadeTo2(fadeRed, fadeGreen, fadeBlue, fadeRed2, fadeGreen2, fadeBlue2, fadeDelay, fadeAmount);
}
// 1 farve
if ((leds[1].r == fadeRed) && (leds[1].g == fadeGreen) && (leds[1].b == fadeBlue)) {
updateFadeColors1 = false;
}
// 2 farver
if ((leds[0].r == fadeRed) && (leds[0].g == fadeGreen) && (leds[0].b == fadeBlue) && (leds[1].r == fadeRed2) && (leds[1].g == fadeGreen2) && (leds[1].b == fadeBlue2)) {
updateFadeColors2 = false;
}
}
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;
}
// Fade an entire array of CRGBs toward a given background color by a given amount
// This function modifies the pixel array in place.
void fadeTowardColor( CRGB* L, uint16_t N, const CRGB& bgColor, uint8_t fadeAmount)
{
for( uint16_t i = 0; i < N; i++) {
fadeTowardColor( L[i], bgColor, fadeAmount);
}
}
void fadeTowardColor2( CRGB* L, uint16_t N, const CRGB& bgColor, const CRGB& bgColor2, uint8_t fadeAmount)
{
for( uint16_t i = 0; i < N; i++) {
if ((i % 2) == 0) {
fadeTowardColor( L[i], bgColor, fadeAmount);
} else {
fadeTowardColor( L[i], bgColor2, fadeAmount);
}
}
}
void fadeTo(byte toRed, byte toGreen, byte toBlue, int fadeDelay, byte fadeAmount) { //byte red, byte green, byte blue, byte toRed, byte toGreen, byte toBlue, int fadeDelay, byte fadeAmount) {
// Syntax: toRed, toGreen, toBlue, fade delay, how much to fade)
CRGB bgColor(toRed, toGreen , toBlue);
fadeTowardColor( leds, NUM_LEDS, bgColor, fadeAmount);
FastLED.show();
FastLED.delay(fadeDelay);
}
void fadeTo2(byte toRed, byte toGreen, byte toBlue, byte toRed2, byte toGreen2, byte toBlue2, int fadeDelay, byte fadeAmount) { //byte red, byte green, byte blue, byte toRed, byte toGreen, byte toBlue, int fadeDelay, byte fadeAmount) {
// Syntax: toRed, toGreen, toBlue, toRed2, toGreen2, toBlue2, fade delay, how much to fade)
CRGB bgColor(toRed, toGreen , toBlue);
CRGB bgColor2(toRed2, toGreen2, toBlue2);
fadeTowardColor2( leds, NUM_LEDS, bgColor, bgColor2, fadeAmount);
FastLED.show();
FastLED.delay(fadeDelay);
}