help me on making the "NEXT" and "PREVIOUS" button for the LED patterns

hello, im trying to make a program that, when i click button 1 it will move to NEXT state and when i press button 2 it will move to PREVIOUS state, i already tried look at some example but it work for NEXT only not on PREVIOUS, please help me…
Thanks…

sketch_may04a.ino (1.3 KB)

Have you read about State Machines?

Work on and add to this example:

byte led1 = 13; 
byte led2 = 12; 
byte button1 = 2;
byte button2 = 3;

//define the available states that we can have for this sketch
enum States{
  stateOne, stateTwo};
//add more states as needed
States mState = stateOne;             //we start out in this machine state

void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  digitalWrite(led1,LOW);
  digitalWrite(led2,HIGH);  
} //END of setup()


void loop()
{

  switch (mState)
  {
    //***************************
  case stateOne:
    {
      if(digitalRead(button1)) // or use:  if(!digitalRead(button1)) 
      {
        digitalWrite(led1,HIGH);
        digitalWrite(led2,LOW);       
        mState = stateTwo;
      }
    }
    break;

    //***************************
  case stateTwo:
    {
      if(digitalRead(button2)) // or use:  if(!digitalRead(button2))
      {
        digitalWrite(led2,HIGH);
        digitalWrite(led1,LOW);       
        mState = stateOne;
      }
    }      
    break;

    //***************************
  default: 
    // default code goes here
    break;

    //***************************

  } //END of switch(mState)

} //END of loop()

I do read about the state machine but the code i make in order for it to be able to back on PREVIOUS state was not working, ill try the example that you gave to me.. thanks in advance.. but if i have 20+ state how do i control it with button 1 and button 2 so that i can make it go NEXT and back to PREVIOUS?

You can add the number of states you need. Start small, add code as needed once things are working.

Example: When you are in state 12 and button 2 is pushed then you set the state to 13 etc. If you are in state 13 and you push button 1 then you set the state to 12 etc.