Turn on LEDS one after another I am trying to turn on LEDs one after the other so that I can start at one end and slowly turn the LEDs until it reaches the middle of the strip. The code works coming from the end of the LED strip, but not when coming from the start of the strip. From the start of the strip, it just turns on all the LEDs up until the midpoint.


int midpoint = 30;
int R = 255;
int G = 0;
int B = 0;
for(int j = 0; j&lt;midpoint; j++){
     //starting from the end, filling towards the middle
        for(int k = NUM_LEDS-j; k &lt; NUM_LEDS; k++){
           leds[k] = CRGB (R, G, B);
        }
//there's some other code here in the interim
FastLED.show();
delay(20);
     //starting from the beginning, filling towards the middle
     //this is the section of code that doesn't work correctly
        for(int l = j - 1; l &lt; midpoint; l++){
           leds[l] = CRGB (R, G, B);
           }
//more interim code
FastLED.show();
delay(20);
}
Okay so i figured it out. The problem is that the for loop is starting at 0 and counting all the way up to the midpoint. What I wanted is for it to light all the LEDs that are at j and below. So I changed it to iterate down instead of up. Here's the new loop:

for(int l = j; l &lt; midpoint &amp; l &gt; -1; l--){
   leds[l] = CRGB (R, G, B);
}


The extra qualifier l &gt; -1 is to make sure that it doesn't try to go below leds[0]