Cant break out off a Loop

Good afternoon everybody.
I am looking for some assistnace in programming some custom DRL's that i have designed for me car. I have it to the point where I can have a different color for each button, but if i put in an animation i cannot exit out of the loop with a button press. I have a 4 button remote that is working

Any help that you all could give me would be much appreciated. I have been working on this for a while now and cannot make any progress.

I have attached the ino file of my sketch

// This is a demonstration on how to use an input device to trigger changes on your neo pixels.
// You should wire a momentary push button to connect from ground to a digital IO pin.  When you
// press the button it will change to a new pixel animation.  Note that you need to press the
// button once to start the first animation!

#include <Adafruit_NeoPixel.h>

#define BUTTON_PIN1   2    // Digital IO pin connected to the button.  This will be
#define BUTTON_PIN2   3    // Digital IO pin connected to the button.  This will be
#define BUTTON_PIN3   4    // Digital IO pin connected to the button.  This will be
#define BUTTON_PIN4   5    // Digital IO pin connected to the button.  This will be

#define PIXEL_PIN    6    // Digital IO pin connected to the NeoPixels.

#define PIXEL_COUNT 48

#define UPDATES_PER_SECOND 100

// Parameter 1 = number of pixels in strip,  neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream, correct for neopixel stick
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

bool oldState1 = HIGH;
bool oldState2 = HIGH;
bool oldState3 = HIGH;
bool oldState4 = HIGH;

int showType = 0;

byte newstate3 = digitalRead(BUTTON_PIN3);
byte newstate2 = digitalRead(BUTTON_PIN2);
byte newstate1 = digitalRead(BUTTON_PIN1);
byte newstate4 = digitalRead(BUTTON_PIN4);

//------------------SETUP------------------
void setup() {
  delay( 2000 ); // power-up safety delay
  
  pinMode(BUTTON_PIN1, INPUT_PULLUP);
  pinMode(BUTTON_PIN2, INPUT_PULLUP);
  pinMode(BUTTON_PIN3, INPUT_PULLUP);
  pinMode(BUTTON_PIN4, INPUT_PULLUP);
  
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  
  theaterChase(strip.Color(127, 127, 127), 75); // White
  theaterChase(strip.Color(127, 127, 127), 50); // White
  theaterChase(strip.Color(127, 127, 127), 25); // White
  colorWipe(strip.Color(127, 127, 127), 25);  // White
}

//------------------MAIN LOOP------------------
void loop() {
  
  // Get current button state.
  bool newState1 = digitalRead(BUTTON_PIN1);
  bool newState2 = digitalRead(BUTTON_PIN2);
  bool newState3 = digitalRead(BUTTON_PIN3);
  bool newState4 = digitalRead(BUTTON_PIN4);
  

  if ((oldState1 == LOW) && (newState1 == HIGH)) {
    shortKeyPressA();
  }
  oldState1 = newState1;


  if ((oldState2 == LOW) && (newState2 == HIGH)) {
    shortKeyPressB();
  }
  oldState2 = newState2;



  if ((oldState3 == LOW) && (newState3 == HIGH)) {
    shortKeyPressC();
  }
  oldState3 = newState3;


  if ((oldState4 == LOW) && (newState4 == HIGH)) {
    shortKeyPressD();
  }
  oldState4 = newState4;
 }



void shortKeyPressA() {
  if (digitalRead (BUTTON_PIN1) == HIGH) {
        showType=1;
        startShow(showType);
    }
}

void shortKeyPressB() {
  if (digitalRead (BUTTON_PIN2) == HIGH) {
        showType=3;
        startShow(showType);
    } 
}

void shortKeyPressC() {
  if (digitalRead (BUTTON_PIN3) == HIGH) {
        showType=2;
        startShow(showType);
    } 
}

void shortKeyPressD() {

  if (digitalRead (BUTTON_PIN4) == HIGH) {
        showType=11;
        startShow(showType);
      }

}





  



void startShow(int i) {
  switch(i){
    case 0: colorWipe(strip.Color(0, 0, 0), 50);    // Black/off
            break;
    case 1: colorWipe(strip.Color(127, 127, 127), 50);  // White
            break;
    case 2: colorWipe(strip.Color(0, 255, 0), 50);  // Green
            break;
    case 3: colorWipe(strip.Color(0, 0, 255), 50);  // Blue
            break;
    case 4: theaterChase(strip.Color(127, 127, 127), 50); // White
            break;
    case 5: theaterChase(strip.Color(127,   0,   0), 50); // Red
            break;
    case 6: theaterChase(strip.Color(  0,   0, 127), 50); // Blue
            break;
    case 7: colorWipe(strip.Color(0, 216, 255), 50);  // Grabber Blue
            break;
    //case 8: Strobe(0xff, 0xff, 0xff, 10, 50, 1000);
    //       break;
    //case 9: theaterChaseRainbow(50);
    //        break;
    //case 10:SnowSparkle(0x10, 0x10, 0x10, 20, random(100,1000));
    //        break;
    case 11:  CylonBounce(0xff, 0, 0, 4, 10, 50); break;

  }
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}


//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}


// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}


void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < PIXEL_COUNT; i++ ) {
    setPixel(i, red, green, blue); 
  }
  strip.show();
}





void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
  while(1){
  for(int i = 0; i < PIXEL_COUNT-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue); 
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    strip.show();
    delay(50);
    //   delay(SpeedDelay);
  }
  delay(50);
  //  delay(ReturnDelay);
  for(int i = PIXEL_COUNT-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue); 
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    strip.show();
    delay(50);
  }
  delay(50);
}

}

AdafruitNeopixelDRLTest.ino (6.89 KB)

Remove all delay() from your animations.

I have just tried that and now it runs very quickly. It is very odd. I want to use the adafruilt library. I can make it work with FastLED, but that doesn't support white

but if i put in an animation i cannot exit out of the loop with a button press.

That is because you are using delay() in you animations. The processor is completely tied up during delay() and can't read button or anything. Use millis() for timing like the blink without delay example or the beginner's millis() tutorial shows.

Sorry, that probably isn't enough clues for you to proceed.

Study the BlinkWithoutDelay example. And the sticky post at the top of this forum on "several things".