fastLed Nested loop

Hi Everyone,

I’ve been pulling my hair out for the past few days, trying to program an LED chase into my code, with very little success.

Basically, I have an array of four changeable CRGB colours and one CRGB::Black (blockArray[NUM_PANELS+1]).
I have also defined an amount of LEDs to display each colour, before switching to the next colour (NUM_LEDS_DUMP).

What I want to happen is have NUM_LEDS_DUMP amount of LEDs follow each other up the chase, until reaching the end (NUM_LEDS_CHASE).

So, I’m really trying to send the blockArray up the string in order, until the first LED reaches the end.

I’ve tried (and failed) to do this with nested loops, cascading if statements and leaning on code I could find around the internet.

any pointers in the right direction would be super appreciated.

Thanks,
Andrew

void colourChase(unsigned long currentMillis)//uint32_t colour, uint8_t wait)
{
  if(currentMillis - previousMillis1 > (interval/100)) {
  //   // save the last time you Changed Colours
  previousMillis1 = currentMillis;

    // if( dumpCount < NUM_LEDS_DUMP)  {
    //   dumpCount++;
    // }
    // if( dumpCount >= NUM_LEDS_DUMP && currentColour > NUM_PANELS)  {
    //   currentColour++;
    // }
    // leds[NUM_LEDS_RING*NUM_PANELS+1] = blockArray[currentColour];

    // if( ledNumber < NUM_LEDS_CHASE)  {
    //   ledNumber++;
    // } else {
    //   colourDump(currentMillis);
    //   currentColour = 0;
    // } 
    
    if( dumpCount < NUM_LEDS_DUMP)  {
      dumpCount++;
    } else if( currentColour < NUM_PANELS)  {
        currentColour++;
        dumpCount = 0;
    } else {
      currentColour = 4;
    }    
      
    
    //   if( dumpCount < NUM_LEDS_DUMP)  {
    //     dumpCount++;
    //   }else  {
    //     dumpCount = 0;
    //   }
    //   if( dumpCount == NUM_LEDS_DUMP) {
    //     currentColour++;
    //   }
    //   if( currentColour > NUM_PANELS)  {
    //     currentColour = 4;//NUM_PANELS+1;
    leds[NUM_LEDS_RING*NUM_PANELS] = blockArray[currentColour];
    // leds[NUM_LEDS_RING*NUM_PANELS+1] = leds[NUM_LEDS_RING*NUM_PANELS];
    for( ledNumber = 0; ledNumber < NUM_LEDS_CHASE-1; ledNumber++)  {
      leds[NUM_LEDS_RING*NUM_PANELS+ledNumber+1] = leds[NUM_LEDS_RING*NUM_PANELS+ledNumber];
      delay(5);
      FastLED.show();
      if( ledNumber == NUM_LEDS_CHASE) {
        break;
      }
    }
    // addGlitter(80);
    FastLED.show();
 
    

    // for( ledNumber = 0; ledNumber < NUM_LEDS_CHASE; ledNumber++)  {

    //   if( dumpCount < NUM_LEDS_DUMP)  {
    //     dumpCount++;
    //   }else  {
    //     dumpCount = 0;
    //   }
    //   if( dumpCount == NUM_LEDS_DUMP) {
    //     currentColour++;
    //   }
    //   if( currentColour > NUM_PANELS)  {
    //     currentColour = 4;//NUM_PANELS+1;
    //   }
    //   leds[NUM_LEDS_RING*NUM_PANELS+ledNumber] = blockArray[currentColour];
    //   // leds[NUM_LEDS_RING*NUM_PANELS+ledNumber+1] = ledStore[NUM_LEDS_RING*NUM_PANELS+ledNumber];

      // delay(5); 

    // }
    // if( ledNumber >= NUM_LEDS_CHASE) { 
    //   colourDump(currentMillis);
    // }
  }
  // for( ledNumber = 0 ledNumber< NUM_LEDS_CHASE; ledNumber++)  {
  //   for( currentColour = 0; currentColour < NUM_PANELS; currentColour++) {
  //     for( dumpCount = 0; dumpCount < NUM_LEDS_DUMP; dumpCount++) {
  //     }
  //   }
  
  // 
  return;
}

void colourDump(unsigned long currentMillis)
{
  //if(currentMillis - previousMillis1 > (interval/20)) {
  //   // save the last time you Changed Colours
  //previousMillis1 = currentMillis;
  currentColour = 0;
  ledNumber = 0;
  //}
  return;
}

just to clarify, do you want to do something like the beginning of this video? If so, read on.

A good place to start might be the “‘Moving’ an LED” example in the FastLED documentation. Modifying that example for multiple LEDs moving forwards is simply delaying the “erase” like this:

for (int dot = 0; dot < NUM_LEDS; dot++) {
  leds[dot] = CRGB::Blue;
  FastLED.show();
  // clear the trailing led for the next time around the loop
  if (dot >= 3)
    leds[dot - 3] = CRGB::Black;
  delay(30);
}

This doesn’t handle clearing the end LEDs the last time through the loop, but i hope it’s enough to get you started.

Great. That's kind of the effect I'm going for (minus the music), and have successfully implemented, but not quite.

If you can imagine a "block" of colour, followed by another "block" * NUM_PANELS (4) then just black, until the first "block" reaches the last led in the array.

I'll try the moving example you've given, I don't know how I'd missed that, I'm using the missing_dot_chase elsewhere in this program, but couldn't quite get it play nice inside this function.

Thanks.