Modified FastLED DemoReel problem...

Hi all,
I'm new to arduino and C++ but have some basic VBA coding experience. I've modified some code and it works in one situation but not another which I cannot figure out. Hope someone can spot what the problem is....

I've inserted a function (theaterChaseRainbow) from the tweaking4all site into the fastLED demo reel. The problem is related to this part of the code (see below stripped back for clarity)...

SimplePatternList gPatterns = {confetti, theaterChaseRainbow, confetti };

In this situation, the function "confetti" loops continuously for 10 s then moves to "theaterChaseRainbow" as expected. I was then expecting theaterChaseRainbow to keep looping continuously and then switch back to confetti in a further 10 s, however, once "theaterChaseRainbow" is called it only executes briefly and then stops. If the only function listed in gPatterns is theaterchaseRainbow, then it executes continuously (as expected).

Why is theaterChaseRainbow not executing continuously for 10 s and then calling confetti again as instructed by the line above?

Any help much appreciated. Sorry for the n00b question.

void setup() {
  FastLED.addLeds<LED_TYPE,DATA_PIN_1,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
}


typedef void (*SimplePatternList[])();

   SimplePatternList gPatterns = {confetti, theaterChaseRainbow, confetti };

   uint8_t gCurrentPatternNumber = 0;          // Index number of which pattern is current
   uint8_t gHue = 0;                           // rotating "base color" used by many of the patterns

 
void loop()
{               
  gPatterns[gCurrentPatternNumber]();         // Call the current pattern function once, updating the 'leds' array


  FastLED.show();  

  // do some periodic updates
  EVERY_N_MILLISECONDS( 20 ) { gHue++; } 	// slowly cycle the "base color" through the rainbow
  EVERY_N_SECONDS( 10 ) { nextPattern(); } 	// change patterns periodically

}

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

void nextPattern()
{
  // add one to the current pattern number, and wrap around at the end
  gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}


void confetti() 
{
  // random colored speckles that blink in and fade smoothly
  fadeToBlackBy( leds, NUM_LEDS, 10);
  int pos = random16(NUM_LEDS);
  leds[pos] += CHSV( gHue + random8(50), 200, 255);
}


void theaterChaseRainbow() {  
  byte *c;
 
  for (int j=0; j < 255; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 20; q++) {
        for (int i=0; i < NUM_LEDS; i=i+20) {
        c = Wheel( (i+j) % 255);
        setPixel(i+q, *c, *(c+1), *(c+2));   
          
        }
        FastLED.show();
       
        delay(30);
        for (int i=0; i < NUM_LEDS; i=i+20) {
          fadeToBlackBy( leds, NUM_LEDS, 8);
          
        }
      }
    } 
}
    for (int q=0; q < 20; q++) {
        for (int i=0; i < NUM_LEDS; i=i+20) {
        setPixel(i+q, *c, *(c+1), *(c+2));

i can reach 240, q 19, 259 is outside the array.

Whandall:

    for (int q=0; q < 20; q++) {

for (int i=0; i < NUM_LEDS; i=i+20) {
        setPixel(i+q, *c, *(c+1), *(c+2));




i can reach 240, q 19, 259 is outside the array.

Thanks Whandall. NUM_LEDS = 150 in this case so I reset that to 130 and its working as expected. Nice spot :wink: