need advise/help on adding a momentary switch to control different patterns Led

Hi Everyone Hope all is well,ive recently begun to code(Total noobie)and wanted to add a momentary switch to my arduino which will be connected to my rgb led lights,what i'm trying to do is to be able to control the different colours of the knight rider,im using NeoPixel-KnightRider library as well as the Adafruit NeoPixel library,with the help of some examples code i was able to find an example code from the neo pixel library which showed me how to control the example code using the momentary switch its just that when ive added the code to example code i keep getting a bunch of errors,i'm hoping someone can point me in the right direction

link to the original knight rider code: NeoPixel-KnightRider/NeoPixel_KnightRider.ino at master · technobly/NeoPixel-KnightRider · GitHub

#include <Adafruit_NeoPixel.h>

// SETUP YOUR OUTPUT PIN AND NUMBER OF PIXELS/Switch
#define BUTTON_PIN   2 
#define PIXEL_PIN    6 
#define PIXEL_COUNT 16

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800)

;bool oldState = HIGH;
int showType = 0;

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  // Get current button state.
  bool newState = digitalRead(BUTTON_PIN);

  // Check if state changed from high to low (button press).
  if (newState == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      showType++;
      if (showType > 9)
        showType=0;
      startShow(showType);
    }
  }

  // Set the last button state to the old state.
  oldState = newState;
}

// Iterate through a whole rainbow of colors
  for(byte j=0; j<252; j+=7) {
    knightRider(1, 16, 2, colorWheel(j)); // Cycles, Speed, Width, RGB Color
  }
  clearStrip();
  
  
}


void knightRider(uint16_t cycles, uint16_t speed, uint8_t width, uint32_t color) {
  uint32_t old_val[NUM_PIXELS]; // up to 256 lights!
  // Larson time baby!
  for(int i = 0; i < cycles; i++){
    for (int count = 1; count<NUM_PIXELS; count++) {
      strip.setPixelColor(count, color);
      old_val[count] = color;
      for(int x = count; x>0; x--) {
        old_val[x-1] = dimColor(old_val[x-1], width);
        strip.setPixelColor(x-1, old_val[x-1]); 
      }
      strip.show();
      delay(speed);
    }
    for (int count = NUM_PIXELS-1; count>=0; count--) {
      strip.setPixelColor(count, color);
      old_val[count] = color;
      for(int x = count; x<=NUM_PIXELS ;x++) {
        old_val[x-1] = dimColor(old_val[x-1], width);
        strip.setPixelColor(x+1, old_val[x+1]);
      }
      strip.show();
      delay(speed);
    }
  }
}

void clearStrip() {
  for( int i = 0; i<NUM_PIXELS; i++){
    strip.setPixelColor(i, 0x000000); strip.show();
  }
}

uint32_t dimColor(uint32_t color, uint8_t width) {
   return (((color&0xFF0000)/width)&0xFF0000) + (((color&0x00FF00)/width)&0x00FF00) + (((color&0x0000FF)/width)&0x0000FF);
}

// Using a counter and for() loop, input a value 0 to 251 to get a color value.
// The colors transition like: red - org - ylw - grn - cyn - blue - vio - mag - back to red.
// Entering 255 will give you white, if you need it.
uint32_t colorWheel(byte WheelPos) {
byte state = WheelPos / 21;
void startShow(int i) {
  switch(i){
    case 0: colorWipe(strip.Color(0, 0, 0), 50);    // Black/off
            break;
    case 1: return strip.Color(255, 0, 255 - ((((WheelPos % 21) + 1) * 6) + 127)); 
            break;
    case 2: return strip.Color(255, ((WheelPos % 21) + 1) * 6, 0); 
            break;
    case 3: return strip.Color(255, (((WheelPos % 21) + 1) * 6) + 127, 0); 
            break;
    case 4: return strip.Color(255 - (((WheelPos % 21) + 1) * 6), 255, 0); 
            break;
    case 5: return strip.Color(255 - (((WheelPos % 21) + 1) * 6) + 127, 255,0); 
            break;
    case 6: return strip.Color(0, 255, ((WheelPos % 21) + 1) * 6); 
            break;
    case 7: return strip.Color(0, 255, (((WheelPos % 21) + 1) * 6) + 127); 
            break;
    case 8: return strip.Color(0, 255 - (((WheelPos % 21) + 1) * 6), 255); 
            break;
    case 9: return strip.Color(0, 255 - ((((WheelPos % 21) + 1) * 6) + 127), 255); 
            break;
    case 10: return strip.Color(((WheelPos % 21) + 1) * 6, 0, 255); 
            break;
    case 11: return strip.Color((((WheelPos % 21) + 1) * 6) + 127, 0, 255); 
            break;
    case 12: return strip.Color(255, 0, 255 - (((WheelPos % 21) + 1) * 6)); 
            break;
    default l3: return strip.Color(0, 0, 0); 
            break;

  }
}
    // Short delay to debounce button.

delay(20);

Yes, that will debounce the button but it's going to mess up your LED pattern injecting a 20ms delay like that. Look around for better debounce code using millis().

Your main loop() function ends just after oldState = newState;. Then you have a lot of code which is outside any function. (Use the control-T autoformat to see the problem more clearly.) You should probably delete the } at that point.

uint32_t colorWheel(byte WheelPos) {

byte state = WheelPos / 21;
  void startShow(int i) {
    switch (i) {
      case 0: colorWipe(strip.Color(0, 0, 0), 50);    // Black/off
        break;
      case 1: return strip.Color(255, 0, 255 - ((((WheelPos % 21) + 1) * 6) + 127));
        break;

What happened here? It looks like you have a function definition inside another function. I think you need a function which takes two parameters, the WheelPos and the showType. And what does state do? You assign it a value and then never use it.

  // Iterate through a whole rainbow of colors

for (byte j = 0; j < 252; j += 7) {
    knightRider(1, 16, 2, colorWheel(j)); // Cycles, Speed, Width, RGB Color
  }

Yes, it will do that. But the rainbow animation is going to take a lot of time with hundreds and hundreds of 16ms delays. Maybe it takes a few seconds. During that time, you're not looking at the button so pressing it will do nothing.

You need to totally rewrite this section along the lines of Blink-Without-Delay. (Look for it in File->Examples->02 Digital.) Make each call to the animation only advance the animation by one step. Then you need to only call that function once every 16ms and all of the rest of the time you can be checking the button.

thank you for your advise i will start to get to work on it hopefully i will be able to figure this out if you dont mind me asking if i want to redo everything like start over and do my own code instead of copying someone else code where do i start?

You start from Robin's Planning and Implementing an Arduino Program