Using one button as on/off and another button as a cycle button

Hi all,

I've been at this for a few days now with no success with regard to my end goal. I want to control multiple LED strips with two buttons. button1 is a latching switch, so I'm using it as my on/off switch and button2 is a momentary switch. When button1 is on, I want button2, when pressed, to cycle through the various cases in the switch statement. That is the basic idea. Once I get that down, I would like to add two more scenarios. The first, is that when button2 is cycling, if I "release" button1 so that it is not pushed to LOW, i would like for the lights to go off at whatever point they are in the switch. Additionally, I would like it so that if I press button2 while it's performing any case, it "interrupts" that case and moves on to the next case immediately. If I'm on a particular case, and I don't press button2, I would like that current case to loop until I press button2 to move onto the next case. Basically, I'm programming different "scenes" for the lights and button2 is used to choose which scene I want.

So far, I have been able to program so that when button1 is pressed and latched, the lights are "ready". Now, when I push button2, it just cycles through all of the cases in the switch without breaking at all. I'm quite new to programming, so I can't see what i'm doing wrong here. I'm sure it has something to do with my brackets and the location of the code. The code I have so far is pasted below. Any help would be greatly appreciated. Thanks in advance:

const int  button1Pin = 2;
const int  button2Pin = 3;

bool button1State = LOW;         
bool button2State = LOW;
bool oldState = HIGH;
int showType = 0;

void setup() {
  // initialize the button pin as a input:
  pinMode(button1Pin, INPUT_PULLUP);
  pinMode(button2Pin, INPUT_PULLUP);
  strip_a.begin();
  strip_b.begin();
  strip_c.begin();
  strip_d.begin();
  strip_e.begin();
  strip_f.begin();
  strip_a.show();
  strip_b.show();
  strip_c.show();
  strip_d.show();
  strip_e.show();
  strip_f.show();
}


void loop() {
  // read the pushbutton input pin:
  button1State = digitalRead(button1Pin);

  if (button1State == LOW && oldState == HIGH) {
    button2State = digitalRead(button2Pin);
  
  // Check if state changed from high to low (button press).
  if (button2State == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    button2State = digitalRead(button2Pin);
    if (button2State == LOW) {
      showType++;
      if (showType > 7)
        showType=1;
      startShow(showType);    
  }  
}
  // Set the last button state to the old state.
   oldState == button2State;     
  }
}

void startShow(int i) {
switch(i){
  case 1: colorWipe(strip_a.Color(81, 224, 214), 25); // Teal 
          break;
  case 2: colorWipe(strip_a.Color(127, 9, 237), 25); // Purple  
          break;
  case 3: colorWipe(strip_a.Color(222, 163, 0), 25); // Gold 
          break;
  case 4: colorWipe(strip_a.Color(0, 0, 255), 25); // Blue  
          break;
  case 5: colorWipeXmas(25); // X-mas
          break;
  case 6: rainbowCycle(10);
          break;
  case 7: colorWipe(strip_a.Color(4, 110, 181), 0);
          flashRandom(5, 40);  // first number is 'wait' delay, shorter num == shorter twinkle
          flashRandom(5, 40);  // second number is how many neopixels to simultaneously light up
          flashRandom(5, 40);
          break;
  }
}
bool button1State = LOW;         
bool button2State = LOW;
bool oldState = HIGH;

Boolean variables are for true/false. Byte is for HIGH/LOW.

Old state of which pin?

You are trying to use the oldState variable to store the previous state of both switches. That isn't going to work.

Thanks PaulS, that definitely pointed me in the right direction. I'm already making some progress. Turns out I found an error in my colorWipe code, which was manifesting itself in my switch as not breaking. Thanks again!