Responsive Push Button

Hi,

I'm using a FastLed.h code on an Arduino Uno which contains IF statements to change the pattern of the LEDs.

I would like to install a push button to trigger the switching between patterns;
button press
pattern = pattern + 1
If pattern >=7 then pattern = 1

The problem I'm having is the button is unresponsive and the pattern is very slow to change if at all, I think it's getting stuck in the current IF statement before registering the change.
When viewing Serial.Print it doesn't change and then it will skip numbers and just be very uncooperative.

I have tried using polling and interrupt and I could get neither to work. I also tried to switch to Cases but I couldn't get past all the errors.

I was hoping someone could help me with my code to make it responsive and resilient. Happy to negotiate a reasonable fee for said work as I am very new to this.

Thank you
Todd

Post your code.

Likely you have blocking delay statements in the pattern routines, that don't allow you to check the button.

I think anyone who wants to quote would in any case need to see your existing code and circuit schematic so they know what they're dealing with in order to scope the work. You could save time and lots of back and forth by providing those now.

I've never used Fastled, and don't have the right hardware so it can't be me.

Code...

#include <FastLED.h>

#define LED_PIN             7
#define NUM_LEDS            256
#define LED_TYPE            WS2812B
#define COLOR_ORDER         GRB
#define DEFAULT_FRAME_RATE  20
#define BRIGHTNESS          150    // 255 is brightest

// Pattern modes must be less than 10
#define CYCLE                        1
#define SINGLE_PANEL_BACK_AND_FORTH  2
#define MULTI_PANEL                  3
#define RAINBOW                      4
#define SINGLE_PANEL_PULL_FORWARD    5
#define GRADIENT_PULSE               6


CRGB leds[NUM_LEDS];

CRGB rainbowPalette[16] =
  {
    { 255,   0,   0 },
    { 255,  66,   0 },
    { 255, 192,   0 },
    { 222, 255,   0 },
    { 126, 255,   0 },
    {  30, 255,   0 },
    {   0, 255,  40 },
    {   0, 255, 162 },
    {   0, 252, 255 },
    {   0, 162, 255 },
    {   0,  66, 255 },
    {  30,   0, 255 },
    {  66,   0, 255 },
    { 180,   0, 255 },
    { 255,   0, 192 },
    { 255,   0,  96 }
  };

CRGB gradientTrailPalette[16];

CRGB longBufferPalette[32];

int gradientArray[16] =
  { 255, 221, 187, 153, 119, 85, 51, 17, 0, 0, 0, 0, 0, 0, 0, 0 };

int rowIndex = 0;
int ledsPerRow = 16;
int numPanels = 16;
int framesPerSecond = DEFAULT_FRAME_RATE;
int currentBrightness = BRIGHTNESS;
byte currentGradientPulseIteration = 0;

int patternMode = 3;                                      ////Pattern Mode is the KEY, Look here - change the number in the loop via button press

void setup()
{
  Serial.begin( 115200 );
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
  
  delay( 3000 ); // power-up safety delay

  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    
  FastLED.setBrightness( BRIGHTNESS );


}

void loop()
{
  {
    FastLED.clear();
    FastLED.show();
  }
  
  if ( patternMode == CYCLE )
  {
    // Single colored panels moving back and forth
    for ( int inx = 0; patternMode == CYCLE && inx < 3; inx++ )
    {
        cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
        cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, false );
        cycleBySinglePanel( CRGB::Indigo, ledsPerRow, numPanels, framesPerSecond, true );
        cycleBySinglePanel( CRGB::Indigo, ledsPerRow, numPanels, framesPerSecond, false );
        cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
        cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, false );
        cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
        cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, false );
    }

    // Single colored panels moving forward only
    for ( int inx = 0; patternMode == CYCLE && inx < 3; inx++ )
    {
        cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
        cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
        cycleBySinglePanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, true );
        cycleBySinglePanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, true );
        cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
        cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
        cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
        cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
    }

    // Moving "train" of 16 contiguous panels
    for ( int inx = 0; patternMode == CYCLE && inx < 2; inx++ )
    {
        cycleFillPanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
        cycleFillPanel( CRGB::Black, ledsPerRow, numPanels, framesPerSecond, true );
        cycleFillPanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, true );
        cycleFillPanel( CRGB::Black, ledsPerRow, numPanels, framesPerSecond, true );
        cycleFillPanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
        cycleFillPanel( CRGB::Black, ledsPerRow, numPanels, framesPerSecond, true );
        cycleFillPanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
        cycleFillPanel( CRGB::Black, ledsPerRow, numPanels, framesPerSecond, true );
        cycleFillPanel( CRGB::Purple, ledsPerRow, numPanels, framesPerSecond, true );
        cycleFillPanel( CRGB::Black, ledsPerRow, numPanels, framesPerSecond, true );
    }

    // Moving rainbow colors
    for ( int jnx = 0; patternMode == CYCLE && jnx < 10; jnx++ )
    {
      for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
      {
        cycleRainbow( numPanels - 1 - inx, ledsPerRow, numPanels );   
      }
    }

    currentGradientPulseIteration = 0;

    for ( int jnx = 0; patternMode == CYCLE && jnx < 13; jnx++ )
    {
      Serial.print( "jnx = " );
      Serial.print( jnx );
      Serial.print( " : currentGradientPulseIteration = " );
      Serial.println( currentGradientPulseIteration );
       
      // Gradient pulse
      // Start from black to red
      if ( currentGradientPulseIteration == 0 )
      {
        for ( int inx = 0; inx < 16; inx++ )
        {
          longBufferPalette[inx] = CRGB::Black;
        }
  
        for ( int inx = 16; inx < 32; inx++ )
        {
          longBufferPalette[inx][0] = gradientArray[inx - 16];
          longBufferPalette[inx][1] = 0;
          longBufferPalette[inx][2] = 0;
        }
  
        for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
        {
          cycleBufferPalette( inx, ledsPerRow, numPanels );
        }
      }
      else if ( currentGradientPulseIteration == 1 )
      {
        // Then red to yellow
        for ( int inx = 0; inx < 16; inx++ )
        {
          longBufferPalette[inx][0] = gradientArray[inx];
          longBufferPalette[inx][1] = 0;
          longBufferPalette[inx][2] = 0;
        }
  
        for ( int inx = 16; inx < 32; inx++ )
        {
          longBufferPalette[inx][0] = gradientArray[inx - 16];
          longBufferPalette[inx][1] = gradientArray[inx - 16];
          longBufferPalette[inx][2] = 0;
        }
  
        for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
        {
          cycleBufferPalette( inx, ledsPerRow, numPanels );
        }
      }
      else if ( currentGradientPulseIteration == 2 )
      {
        // Then yellow to green
        for ( int inx = 0; inx < 16; inx++ )
        {
          longBufferPalette[inx][0] = gradientArray[inx];
          longBufferPalette[inx][1] = gradientArray[inx];
          longBufferPalette[inx][2] = 0;
        }
  
        for ( int inx = 16; inx < 32; inx++ )
        {
          longBufferPalette[inx][0] = 0;
          longBufferPalette[inx][1] = gradientArray[inx - 16];
          longBufferPalette[inx][2] = 0;
        }
  
        for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
        {
          cycleBufferPalette( inx, ledsPerRow, numPanels );
        }
      }
      else if ( currentGradientPulseIteration == 3 )
      {
        // Then green to cyan
        for ( int inx = 0; inx < 16; inx++ )
        {
          longBufferPalette[inx][0] = 0;
          longBufferPalette[inx][1] = gradientArray[inx];
          longBufferPalette[inx][2] = 0;
        }
  
        for ( int inx = 16; inx < 32; inx++ )
        {
          longBufferPalette[inx][0] = 0;
          longBufferPalette[inx][1] = gradientArray[inx - 16];
          longBufferPalette[inx][2] = gradientArray[inx - 16];
        }
  
        for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
        {
          cycleBufferPalette( inx, ledsPerRow, numPanels );
        }
      }
      else if ( currentGradientPulseIteration == 4 )
      {
        // Then cyan to blue
        for ( int inx = 0; inx < 16; inx++ )
        {
          longBufferPalette[inx][0] = 0;
          longBufferPalette[inx][1] = gradientArray[inx];
          longBufferPalette[inx][2] = gradientArray[inx];
        }
  
        for ( int inx = 16; inx < 32; inx++ )
        {
          longBufferPalette[inx][0] = 0;
          longBufferPalette[inx][1] = 0;
          longBufferPalette[inx][2] = gradientArray[inx - 16];
        }
  
        for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
        {
          cycleBufferPalette( inx, ledsPerRow, numPanels );
        }
      }
      else if ( currentGradientPulseIteration == 5 )
      {
        // Then blue to magenta
        for ( int inx = 0; inx < 16; inx++ )
        {
          longBufferPalette[inx][0] = 0;
          longBufferPalette[inx][1] = 0;
          longBufferPalette[inx][2] = gradientArray[inx];
        }
  
        for ( int inx = 16; inx < 32; inx++ )
        {
          longBufferPalette[inx][0] = gradientArray[inx - 16];
          longBufferPalette[inx][1] = 0;
          longBufferPalette[inx][2] = gradientArray[inx - 16];
        }
  
        for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
        {
          cycleBufferPalette( inx, ledsPerRow, numPanels );
        }
      }
      else if ( currentGradientPulseIteration == 6 )
      {
        // Then magenta to red
        for ( int inx = 0; inx < 16; inx++ )
        {
          longBufferPalette[inx][0] = gradientArray[inx];
          longBufferPalette[inx][1] = 0;
          longBufferPalette[inx][2] = gradientArray[inx];
        }
  
        for ( int inx = 16; inx < 32; inx++ )
        {
          longBufferPalette[inx][0] = gradientArray[inx - 16];
          longBufferPalette[inx][1] = 0;
          longBufferPalette[inx][2] = 0;
        }
  
        for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
        {
          cycleBufferPalette( inx, ledsPerRow, numPanels );
        }
      }
  
      currentGradientPulseIteration++;
  
      if ( currentGradientPulseIteration == 7 )
      {
        // Don't want to go back to 0 because that
        // was just the initializer with a starting block of black.
        currentGradientPulseIteration = 1;
      }

    }

  }
  else if ( patternMode == SINGLE_PANEL_BACK_AND_FORTH )
  {
      cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
      cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, false );
      cycleBySinglePanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, true );
      cycleBySinglePanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, false );
      cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
      cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, false );
      cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
      cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, false );
  }
  
  else if ( patternMode == SINGLE_PANEL_PULL_FORWARD )
  {
    
      cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
      cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
      cycleBySinglePanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, true );
      cycleBySinglePanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, true );
      cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
      cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
      cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
      cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
    
  }
  else if ( patternMode == MULTI_PANEL )
  {

 
     cycleFillPanel( CRGB::SkyBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::SlateBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::DarkSlateBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::Aqua, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::DeepSkyBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::DodgerBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::PowderBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::SteelBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::LightBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::LightSkyBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::LightSteelBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::MediumAquamarine, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::MidnightBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::MediumBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::RoyalBlue, ledsPerRow, numPanels, framesPerSecond, true );
     cycleFillPanel( CRGB::Teal, ledsPerRow, numPanels, framesPerSecond, true );

  }
  else if ( patternMode == RAINBOW )
  {
    for ( int inx = 0; patternMode == RAINBOW && inx < numPanels; inx++ )
    {
      cycleRainbow( numPanels - 1 - inx, ledsPerRow, numPanels );    
    }
  }
  if ( patternMode == GRADIENT_PULSE )
  {
    // Cycle colors

    // Start from black to red
    if ( currentGradientPulseIteration == 0 )
    {
      for ( int inx = 0; inx < 16; inx++ )
      {
        longBufferPalette[inx] = CRGB::Black;
      }

      for ( int inx = 16; inx < 32; inx++ )
      {
        longBufferPalette[inx][0] = gradientArray[inx - 16];
        longBufferPalette[inx][1] = 0;
        longBufferPalette[inx][2] = 0;
      }

      for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
      {
        cycleBufferPalette( inx, ledsPerRow, numPanels );
      }
    }
    else if ( currentGradientPulseIteration == 1 )
    {
      // Then red to yellow
      for ( int inx = 0; inx < 16; inx++ )
      {
        longBufferPalette[inx][0] = gradientArray[inx];
        longBufferPalette[inx][1] = 0;
        longBufferPalette[inx][2] = 0;
      }

      for ( int inx = 16; inx < 32; inx++ )
      {
        longBufferPalette[inx][0] = gradientArray[inx - 16];
        longBufferPalette[inx][1] = gradientArray[inx - 16];
        longBufferPalette[inx][2] = 0;
      }

      for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
      {
        cycleBufferPalette( inx, ledsPerRow, numPanels );
      }
    }
    else if ( currentGradientPulseIteration == 2 )
    {
      // Then yellow to green
      for ( int inx = 0; inx < 16; inx++ )
      {
        longBufferPalette[inx][0] = gradientArray[inx];
        longBufferPalette[inx][1] = gradientArray[inx];
        longBufferPalette[inx][2] = 0;
      }

      for ( int inx = 16; inx < 32; inx++ )
      {
        longBufferPalette[inx][0] = 0;
        longBufferPalette[inx][1] = gradientArray[inx - 16];
        longBufferPalette[inx][2] = 0;
      }

      for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
      {
        cycleBufferPalette( inx, ledsPerRow, numPanels );
      }
    }
    else if ( currentGradientPulseIteration == 3 )
    {
      // Then green to cyan
      for ( int inx = 0; inx < 16; inx++ )
      {
        longBufferPalette[inx][0] = 0;
        longBufferPalette[inx][1] = gradientArray[inx];
        longBufferPalette[inx][2] = 0;
      }

      for ( int inx = 16; inx < 32; inx++ )
      {
        longBufferPalette[inx][0] = 0;
        longBufferPalette[inx][1] = gradientArray[inx - 16];
        longBufferPalette[inx][2] = gradientArray[inx - 16];
      }

      for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
      {
        cycleBufferPalette( inx, ledsPerRow, numPanels );
      }
    }
    else if ( currentGradientPulseIteration == 4 )
    {
      // Then cyan to blue
      for ( int inx = 0; inx < 16; inx++ )
      {
        longBufferPalette[inx][0] = 0;
        longBufferPalette[inx][1] = gradientArray[inx];
        longBufferPalette[inx][2] = gradientArray[inx];
      }

      for ( int inx = 16; inx < 32; inx++ )
      {
        longBufferPalette[inx][0] = 0;
        longBufferPalette[inx][1] = 0;
        longBufferPalette[inx][2] = gradientArray[inx - 16];
      }

      for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
      {
        cycleBufferPalette( inx, ledsPerRow, numPanels );
      }
    }
    else if ( currentGradientPulseIteration == 5 )
    {
      // Then blue to magenta
      for ( int inx = 0; inx < 16; inx++ )
      {
        longBufferPalette[inx][0] = 0;
        longBufferPalette[inx][1] = 0;
        longBufferPalette[inx][2] = gradientArray[inx];
      }

      for ( int inx = 16; inx < 32; inx++ )
      {
        longBufferPalette[inx][0] = gradientArray[inx - 16];
        longBufferPalette[inx][1] = 0;
        longBufferPalette[inx][2] = gradientArray[inx - 16];
      }

      for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
      {
        cycleBufferPalette( inx, ledsPerRow, numPanels );
      }
    }
    else if ( currentGradientPulseIteration == 6 )
    {
      // Then magenta to red
      for ( int inx = 0; inx < 16; inx++ )
      {
        longBufferPalette[inx][0] = gradientArray[inx];
        longBufferPalette[inx][1] = 0;
        longBufferPalette[inx][2] = gradientArray[inx];
      }

      for ( int inx = 16; inx < 32; inx++ )
      {
        longBufferPalette[inx][0] = gradientArray[inx - 16];
        longBufferPalette[inx][1] = 0;
        longBufferPalette[inx][2] = 0;
      }

      for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
      {
        cycleBufferPalette( inx, ledsPerRow, numPanels );
      }
    }

    currentGradientPulseIteration++;

    if ( currentGradientPulseIteration == 7 )
    {
      // Don't want to go back to 0 because that
      // was just the initializer with a starting block of black.
      currentGradientPulseIteration = 1;
    }
  }
}

void cycleBufferPalette( int pStartRowIndex,  // Must be 0 to 16
                         int pLedsPerRow,
                         int pNumPanels
                       )
{
  for ( int inx = 0; inx < pNumPanels; inx++ )
  {
    lightUpRow( longBufferPalette[inx + pStartRowIndex], inx, pLedsPerRow, pNumPanels );
  }
}

void cycleBySinglePanel( CRGB pColor,
                         int  pLedsPerRow,
                         int  pNumPanels,
                         int  pFramesPerSecond,
                         boolean pForward
                       )
{
  for ( int inx = 0; inx < pNumPanels; inx++ )
  {
    if ( pForward )
    {
      lightUpRow( pColor, pNumPanels - 1 - inx, pLedsPerRow, pNumPanels );
      delay( 1000 / pFramesPerSecond );
      clearRow( pNumPanels - 1 - inx, pLedsPerRow, pNumPanels );
    }
    else
    {
      lightUpRow( pColor, inx, pLedsPerRow, pNumPanels );
      delay( 1000 / pFramesPerSecond );
      clearRow( inx, pLedsPerRow, pNumPanels );
    }
  }
}

void cycleFillPanel( CRGB pColor,
                     int  pLedsPerRow,
                     int  pNumPanels,
                     int  pFramesPerSecond,
                     boolean pForward
                   )
{
  for ( int inx = 0; inx < pNumPanels; inx++ )
  {
    if ( pForward )
    {
      lightUpRow( pColor, pNumPanels - 1 - inx, pLedsPerRow, pNumPanels );
      delay( 1000 / pFramesPerSecond );
    }
    else
    {
      lightUpRow( pColor, inx, pLedsPerRow, pNumPanels );
      delay( 1000 / pFramesPerSecond );
    }
  }
}

void cycleGradientTrail( int pStartRowIndex,
                         int pLedsPerRow,
                         int pNumPanels
                       )
{
  int currentPanelIndex = pStartRowIndex;

  for ( int inx = 0; inx < pNumPanels; inx++ )
  {
    currentPanelIndex = pStartRowIndex + inx;

    if ( currentPanelIndex >= pNumPanels )
    {
      currentPanelIndex = currentPanelIndex - pNumPanels;
    }
    
    lightUpRow( gradientTrailPalette[inx], currentPanelIndex, pLedsPerRow, pNumPanels );
  }
}

void cycleRainbow( int pStartRowIndex,
                   int pLedsPerRow,
                   int pNumPanels
                 )
{
  int currentPanelIndex = pStartRowIndex;
  
  for ( int inx = 0; inx < pNumPanels; inx++ )
  {
    currentPanelIndex = pStartRowIndex + inx;
    
    if ( currentPanelIndex >= pNumPanels )
    {
      currentPanelIndex = currentPanelIndex - pNumPanels;            
    }

    lightUpRow( rainbowPalette[inx], currentPanelIndex, pLedsPerRow, pNumPanels );
  }
}

void lightUpRow( CRGB pColor,
                 int  pRowIndex,
                 int  pLedsPerRow,
                 int  pNumPanels
               )
{
  int ledIndex = ( pNumPanels - 1 - pRowIndex ) * pLedsPerRow;
  
  for ( int inx = ledIndex; inx < ledIndex + ledsPerRow; inx++ )
  {
    leds[inx] = pColor;
  }

  FastLED.show();
}

void clearRow( int pRowIndex,
               int pLedsPerRow,
               int pNumPanels
             )
{
  int ledIndex = ( pNumPanels - 1 - pRowIndex ) * pLedsPerRow;
  
  for ( int inx = ledIndex; inx < ledIndex + ledsPerRow; inx++ )
  {
    leds[inx] = CRGB::Black;
  }

  FastLED.show();
}

Thank you, posted now.

Thank you, posted now

Can't see any button code in there anywhere? What did you try?

Your delay() statements will cause a slow response as they basically block the code, and although only 50ms they are within for loops so the delay is multiplied.

Free solution:

Change all of your delay(x); calls to:
if (myDelay(x)) return;

boolen myDelay(unsigned long duration)
{
  unsigned long delayStart = millis();
  while (millis() - delayStart < duration)
  {
    if (digitalRead(ButtonPin == LOW)
      return true;  // Button pressed
  }
  return false; // Delay completed
}

There are cut&dry techniques to de-block your code.
I have an example that has 2 combined sketches with for-loop and delay(s) can only run by themselves so they run serially.
Next example shows converting delays to timers and for loops to if()s with indexes.
Arduino forum thread, you can bookmark the forum in the forum.

Thank you everyone for your help and taking the time to look at this.
It has been solved by one of the amazingly talented people on here.

I'm sorry I could not respond to you all sooner, I exceeded my post limit on the forum and was unable to post yesterday.

Thank you
Todd

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.