Neopixel Patterns with button

Hi, Im fairly new to programing on arduino. Im trying to take a single neopixel v2 and change color states with a push button. I have it down so i can change single colors with the button press with no issues. Im trying to get rainbow color fades and bliking colors in pattern to work with button presses. Ive tried the loop functions and other codes, but to no avail. Anyone that can help me with this code would be greatly appreciated.

#include <Adafruit_NeoPixel.h>

    int buttonPin = 0;    // momentary push button on pin 0
    int oldButtonVal = 0;
    
    #define PIN 1    // Parameter 1 = number of pixels in strip
                          // Parameter 2 = pin number (most are valid)
                          // Parameter 3 = pixel type flags, add together as needed:
                          // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
                          // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
                          // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
                          // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);
    
    int nPatterns = 9;
    int lightPattern = 1;

// the setup routine runs once when you press reset:
    void setup() {
    strip.begin();
    strip.show();                // initialize all pixels to 'off'    
// initialize the BUTTON pin as an input
    pinMode(buttonPin, INPUT);
    digitalWrite(buttonPin, HIGH);  // button pin is HIGH, so it drops to 0 if pressed
}


// Pattern 1 - White light, all LEDs in the strip are white
    void pattern1() {
        strip.setPixelColor(0, strip.Color(255, 255, 255)); // White
        strip.setPixelColor(1, strip.Color(255, 255, 255));
        strip.setPixelColor(2, strip.Color(255, 255, 255));
        strip.setPixelColor(3, strip.Color(255, 255, 255));
        strip.setPixelColor(4, strip.Color(255, 255, 255));
    strip.show();
    }
    
// Pattern 2 - Red light, all LEDs in the strip are red
    void pattern2() {
        strip.setPixelColor(0, strip.Color(255, 0, 0)); // Red
        strip.setPixelColor(1, strip.Color(255, 0, 0));
        strip.setPixelColor(2, strip.Color(255, 0, 0));
        strip.setPixelColor(3, strip.Color(255, 0, 0));
        strip.setPixelColor(4, strip.Color(255, 0, 0));
    strip.show();
    }
    
// Pattern 3 - Orange light, all LEDs in the strip are orange
    void pattern3() {
        strip.setPixelColor(0, strip.Color(255, 128, 0)); // Orange
        strip.setPixelColor(1, strip.Color(255, 128, 0));
        strip.setPixelColor(2, strip.Color(255, 128, 0));
        strip.setPixelColor(3, strip.Color(255, 128, 0));
        strip.setPixelColor(4, strip.Color(255, 128, 0));
    strip.show();
    }

// Pattern 4 - Yellow light, all LEDs in the strip are yellow
    void pattern4() {
        strip.setPixelColor(0, strip.Color(255, 255, 0)); // Yellow
        strip.setPixelColor(1, strip.Color(255, 255, 0));
        strip.setPixelColor(2, strip.Color(255, 255, 0));
        strip.setPixelColor(3, strip.Color(255, 255, 0));
        strip.setPixelColor(4, strip.Color(255, 255, 0));
    strip.show();
    }
    
// Pattern 5 - Green light, all LEDs in the strip are green
    void pattern5() {
        strip.setPixelColor(0, strip.Color(0, 255, 0)); // Green
        strip.setPixelColor(1, strip.Color(0, 255, 0));
        strip.setPixelColor(2, strip.Color(0, 255, 0));
        strip.setPixelColor(3, strip.Color(0, 255, 0));
        strip.setPixelColor(4, strip.Color(0, 255, 0));
    strip.show();
    }

// Pattern 6 - Blue light, all LEDs in the strip are blue
    void pattern6() {
        strip.setPixelColor(0, strip.Color(0, 0, 255)); // Blue
        strip.setPixelColor(1, strip.Color(0, 0, 255));
        strip.setPixelColor(2, strip.Color(0, 0, 255));
        strip.setPixelColor(3, strip.Color(0, 0, 255));
        strip.setPixelColor(4, strip.Color(0, 0, 255));
    strip.show();
    }
    
// Pattern 7 - Violet light, all LEDs in the strip are violet
    void pattern7() {
        strip.setPixelColor(0, strip.Color(127, 0, 255)); // Violet
        strip.setPixelColor(1, strip.Color(127, 0, 255));
        strip.setPixelColor(2, strip.Color(127, 0, 255));
        strip.setPixelColor(3, strip.Color(127, 0, 255));
        strip.setPixelColor(4, strip.Color(127, 0, 255));
    strip.show();
    }

// Pattern 8 - Rainbow light, all LEDs in the strip are different colors
    void pattern8() {
        strip.setPixelColor(0, strip.Color(255, 0, 255)); // Red
        strip.setPixelColor(1, strip.Color(255, 255, 0)); // Yellow
        strip.setPixelColor(2, strip.Color(0, 255, 0)); // Green
        strip.setPixelColor(3, strip.Color(0, 0, 255)); // Blue
        strip.setPixelColor(4, strip.Color(127, 0, 255)); // Violet
    strip.show();
    }

//Pattern 9 - Color Cycle
//    void pattern9() {
//          rainbow(20)
//    }

// the loop routine runs over and over again forever;
void loop() {
  // read that state of the pushbutton value;
  int buttonVal = digitalRead(buttonPin);
  if (buttonVal == LOW && oldButtonVal == HIGH) {// button has just been pressed
    lightPattern = lightPattern + 1;
  }
  if (lightPattern > nPatterns) lightPattern = 1;
  oldButtonVal = buttonVal;
  
  
  switch(lightPattern) {
    case 1:
      pattern1();
      break;
    case 2:
      pattern2();
      break;
    case 3:
      pattern3();
      break;
    case 4:
      pattern4();
      break;
    case 5:
      pattern5();
      break;
    case 6:
      pattern6();
      break;
    case 7:
      pattern7();
      break;
    case 8:
      pattern8();
      break;
  }
}

The code you posted does something. You seem to have forgotten to mention what it actually does.

The fact that you posted at all indicates that the code does not do what you actually want. How what the code actually does differs from what you actually want seems to have been left out of your post, too.

Given these two omissions, it's hard to tell you how to change the code to make it do what you want.

#define PIN 1    // Parameter 1 = number of pixels in strip
                          // Parameter 2 = pin number (most are valid)
...
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);

You've got this thing connected to pin 1?

yes the design works, and yes it is connected correctly.

AWOL:
You've got this thing connected to pin 1?

What I'm having issues with specifically is adding a rainbow fade and "loop"able functions like a color chase and strobe functions to it. I understand i didn't add the code for the fades and such. I was having so many issues trying to add them that i omitted them entirely. I wanted to post a code that i knew worked and see if there was a way to add it based on the code provided or modified in such a way to make it work. I can also get 'strandtest' example to work fine, just haven't been able to find a way to mesh the two codes together to get a working design.

Im basically trying to add all of the color uses of strand test to my existing code and be able to change "patterns" with a button press

The question about connecting the LED strip to pin 1 (and the switch to pin 0) was a hint. Get them off of the hardware serial pins, so you can use Serial to debug your code. Debug-by-guess is the poorest way to debug code.

Aside from the above (using pin 1)...

You declare your strip as 1 LED, but you seem to handle it as a 5 LED strip. strip.setPixelColor(1-4,x,x,x) in each of your patterns won't do anything, seeing as LED's 1-4 don't exist (per your code).

You also seem to (to me at least) to not understand the usage of .Color(). It creates a uint32_t variable that can be easily passed to another function. Your not doing anything with it at all, you're just using it to set values you've already assigned. Drop the .Color's completely. Write it as just strip.setPixelColor(0,r,g,b). where r, g, and b are the identical values you have typed out.

Take a look at Test NeoPixel Strip | NeoPixel Painter | Adafruit Learning System for how they are using .Color to pass the color value to another function.

There may be a better way, but When I want my pixels to fade in or out, or to fade to a different color, I use a for loop:

Fades from black to Red and Back: (I use pix instead of strip)

for(i=0; i <= 255; i+=5)
  {
    pix.setPixelColor(0,i,0,0);
    pix.show();
    delay(50);
  }
  for(i=255; i >=0 ; i-=5)
  {
    pix.setPixelColor(0,i,0,0);
    pix.show();
    delay(50);
  }

And then, to fade from Red to Blue (and stuff in between). replace pix.setPixelColor(0,i,0,0); with pix.setPixelColor(0,i,0,255-i);