Programming question for button to control ws2812b led strip.

Looking to do ws2812b leds on the interior of my car with the stuff i have laying around.
Any idea on how to have a button change the different light patterns modes on the strip?
Like first press, it cycles through the colors of the rainbow, second press it makes the lights flash through colors, third press, i get a solid color, etc.
Been stumped on this for a while :c
The strips have 3 pins, 5v, GND, and data in.

Also looking to possibly have it where on one of the button presses that the microphone sensor kicks in and the colors will change to sound.

Any help on the coding would be greatly appreciated. Thankss!!!
:slight_smile:

For the button, have a look at state change and debouncing. Or just use a simple library like Bounce2.

And for the different modes, just create a global variable that holds the current mode and increment it with every button press (and set it back to 0 when you're at the last mode). Something like:

byte lightMode = 0;
const byte NumberOfModes = 5;


void loop(){
  checkButton();
  
  doLightEffect();
}

void checkButton(){
  button.update();
  if(button.fell()){
    lightMode++;
    if(lightMode >= NumberOfModes){
      lightMode = 0;
    }
  }
}

void doLightEffect(){
  switch(lightMode){
    case 0:
      //rainbow
    break;
    case 2:
      //color flash
    break;
    case 3:
      //solid color
    break;
    case 4:
      //etc
    break;  
  }
}

All the code needs to be non-blocking. So no delay() anywhere. The loop must loop as often as possible.