Hi guys, how would I go about fading a full bright white LED to black over a specific amount of time?
Do you want the light to fade and come back on, in a pulsing manner, or just fade to black and stay there?
@Gustavo_Aldana_WMX66 Just stay there. I’m just having trouble figuring out how to fade to black by a specific amount of time.
from the documentation:
If you want the color to eventually fade all the way to black, use one of these functions:
// Dim a color by 25% (64/256ths)
// eventually fading to full black
leds[i].fadeToBlackBy( 64 );
// Reduce color to 75% (192/256ths) of its previous value
// eventually fading to full black
leds[i].nscale8( 192);
@Tim_Abels thanks but I’m asking about controlling the fade time. Guess I have to do it using a timer and maths or a colour palate?
You’re right, sorry. Recently I did this:
void fadeTo(CRGB newColor, uint32_t fadeTime){
for (uint8_t amount = 0; amount < 255; amount++) {
leds[0] = blend(currentColor, newColor, amount);
FastLED.delay((uint32_t) round(fadeTime*3.9));
// fadeTime[s] * delayTimeUnit / steps == 1000ms / 256 steps = 3.9
}
currentColor = newColor;
return;
}
So FastLED.delay(1000) will delay 1 second. If you fade by 256 steps, every delay in the loop has to be 1000/256 which is 3.9. If it isn’t critical, you should use an integer (in this case 4) resulting in a fade time of 4*256 = 1024ms. The other instructions in the loop take their time too. Hope this helps