Hi all. I'm trying to get a WS2812B LED strip to fade in a sequence of LEDs, but fade in just one at a time and overlapping timing, if possible. I can get the LEDs to turn on in sequence and I can get them all to fade in and out at the same time, but I can't figure out how to combine the two.
Here's the current code I'm working with. The problem is that they fade in incrementally in sequence. What I mean is that they'll all sequentially get set to x brightness, then they'll all get set to x+1, then all to x+2, etc. I don't mind that on the fade out, but it's the fade in that's problematic. What am I doing wrong? Thanks in advance.
double check what fadeLightBy() does. It might fade every led down
what are the for loops for? you have only 1 valid index in there...
it's the same as if you were doing
void loop() {
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) fadeAmount = -fadeAmount ;
for(int i=0;i<7;i++){
leds[i] = CRGB(0x006400);
leds[i].fadeLightBy(brightness);
FastLED.show();
delay(100);
}
}
You could use an HSV representation of your color and fade in or out by changing the V.
PS/
(you code works because 255 can be divided by 15, instead of testing for equality you should test for > or < and of course not go beyond 255 or negative)
@ruilviana That works perfectly, thank you!! I have a couple questions regarding your code so I can learn from this. What does "byte factor" do? Also I see that brightness (int) will be equal to factor (byte) in loop. What sets an int and byte apart in storing a value?