function not recognized in switch

I have a program created where the button after each click moves certain actions. I'm using switch method. All works great except Rotate(). If I call the function directly in the loop function, it works just fine. It just doesn't work in the switch method under the case. Any Ideas? Thanks. Here is the code:

    #define PIN_COUNT 10
    #define UPDATE_DURATION 30
    
    int states[PIN_COUNT];
    int current_pin = 0;
    int dir = 1;
    int update_count = 0;
    
    int ledPins[PIN_COUNT] = {0,1,2,3,4,5,6,7,8,9};
    int switchPin = 13;   // choose the input pin (for a pushbutton)
    
    
        int val;                        // variable for reading the pin status
        int val2;                      // variable for reading the delayed status
        int buttonState;                // variable to hold the button state
        int Mode = 0;              // What mode is the light in?
        boolean modeChanged = false;
        const int NUM_MODES = 14;
    
    /* RGB */
    const int RED_PIN = 10;
    const int GREEN_PIN = 11;
    const int BLUE_PIN = 12;
    int DISPLAY_TIME = 100;
    /* RGB */
        
    
    void setup()
    {
      int index;
     
      for(index = 0; index <= 9; index++)
      {
        pinMode(ledPins[index],OUTPUT);
        // ledPins[index] is replaced by the value in the array.
        // For example, ledPins[0] is 2
      }
      pinMode(switchPin, INPUT);    // Set the switch pin as input
      buttonState = digitalRead(switchPin);   // read the initial state
      /* RGB */
      pinMode(RED_PIN, OUTPUT);
      pinMode(GREEN_PIN, OUTPUT);
      pinMode(BLUE_PIN, OUTPUT);
      /* RGB */
      for ( int i = 0; i < PIN_COUNT; i++ ) {
        pinMode(ledPins[i], OUTPUT);
        states[i] = 0;
      }
    }
    
    
    
    
    
      /* RGB */
    void mainColors()
    {
      // Off (all LEDs off):
    
      digitalWrite(RED_PIN, LOW);
      digitalWrite(GREEN_PIN, LOW);
      digitalWrite(BLUE_PIN, LOW);
    
      delay(1000);
    
      // Red (turn just the red LED on):
    
      digitalWrite(RED_PIN, HIGH);
      digitalWrite(GREEN_PIN, LOW);
      digitalWrite(BLUE_PIN, LOW);
    
      delay(1000);
    
      // Green (turn just the green LED on):
    
      digitalWrite(RED_PIN, LOW);
      digitalWrite(GREEN_PIN, HIGH);
      digitalWrite(BLUE_PIN, LOW);
    
      delay(1000);
    
      // Blue (turn just the blue LED on):
    
      digitalWrite(RED_PIN, LOW);
      digitalWrite(GREEN_PIN, LOW);
      digitalWrite(BLUE_PIN, HIGH);
    
      delay(1000);
    
      // Yellow (turn red and green on):
    
      digitalWrite(RED_PIN, HIGH);
      digitalWrite(GREEN_PIN, HIGH);
      digitalWrite(BLUE_PIN, LOW);
    
      delay(1000);
    
      // Cyan (turn green and blue on):
    
      digitalWrite(RED_PIN, LOW);
      digitalWrite(GREEN_PIN, HIGH);
      digitalWrite(BLUE_PIN, HIGH);
    
      delay(1000);
    
      // Purple (turn red and blue on):
    
      digitalWrite(RED_PIN, HIGH);
      digitalWrite(GREEN_PIN, LOW);
      digitalWrite(BLUE_PIN, HIGH);
    
      delay(1000);
    
      // White (turn all the LEDs on):
    
      digitalWrite(RED_PIN, HIGH);
      digitalWrite(GREEN_PIN, HIGH);
      digitalWrite(BLUE_PIN, HIGH);
    
      delay(1000);
    }
      /* RGB */
    
    void Decade()
    {
      int index;
      int delayTime = 100; // milliseconds to pause between LEDs
      
      
       val = digitalRead(switchPin);      // read input value and store it in val
        delay(10);                         // 10 milliseconds is a good amount of time
        val2 = digitalRead(switchPin);     // read the input again to check for bounces
        if (val == val2) {                 // make sure we got 2 consistant readings!
            if (val != buttonState) {          // the button state has changed!
                if (val == LOW) {                // check if the button is pressed
                    Mode++;
                    if (Mode >= NUM_MODES) {
                        Mode = 0;
                    }
                    modeChanged = true;
                }
            }
            buttonState = val;                 // save the new state in our variable
        }
    
        if (modeChanged) {
            modeChanged = false;
    
            // Now do whatever the lightMode indicates
            switch(Mode) {
            case 0:
                digitalWrite(ledPins[index], LOW);
                digitalWrite(BLUE_PIN, HIGH);
                break;
    
            case 1:
                digitalWrite(ledPins[0], HIGH);
                digitalWrite(RED_PIN, LOW);
                digitalWrite(GREEN_PIN, LOW);
                digitalWrite(BLUE_PIN, LOW);
                break;
    
            case 2:
                digitalWrite(ledPins[1], HIGH);
                break;
    
            case 3:
                digitalWrite(ledPins[2], HIGH);
                break;
                
            case 4:
                digitalWrite(ledPins[3], HIGH);
                break;
                
            case 5:
                digitalWrite(ledPins[4], HIGH);
                break;
                
            case 6:
                digitalWrite(ledPins[5], HIGH);
                break;
                
            case 7:
                digitalWrite(ledPins[6], HIGH);
                break;
                
            case 8:
                digitalWrite(ledPins[7], HIGH);
                break;
                
            case 9:
                digitalWrite(ledPins[8], HIGH);
                break;
                
            case 10:
                digitalWrite(ledPins[9], HIGH);
                break;    
                
            case 11:
                Rotate(); 
                break;
                
            case 12:
                digitalWrite(RED_PIN, HIGH);
                break; 
                
             case 13:
                digitalWrite(GREEN_PIN, HIGH);
                break; 
                         
               
                      
            }
        }
    }
    
      void loop()
    {
      
      Decade();        // RUNTIME!!
    }
      
     void updatePins() {
      for ( int i = 0; i < PIN_COUNT; i++ ) {
        analogWrite(ledPins[i], states[i]);
      }
      delay(6);
    }
    
    void decay() {
      for ( int i = 0; i < PIN_COUNT; i++ ) {
        states[i] = (19*states[i]/20);
      }
    }
    
    void Rotate(){
    decay();
      states[current_pin] = 255 * update_count / UPDATE_DURATION;
      updatePins();
      
      update_count++;
      if ( update_count > UPDATE_DURATION ) {
        update_count = 0;
        current_pin += dir;
        if ( current_pin == 0 ) {
          dir = 1;
        }
      /*  else if ( current_pin == (PIN_COUNT-1) ) {
          dir = -1;
        }*/
        
      }
    }

Have you verified that the Mode variable ever has a value of 11 by printing its value before the switch ?

Note that the states array is of type int but  states[current_pin] = 255 * update_count / UPDATE_DURATION;may not give an integer result.

      if ( update_count > UPDATE_DURATION ) {

And, really, does it make sense to compare a count and a time? If those are not what are stored in those variables (or #define values), the names need changing.

Auto format your code and then repost it. What was the error message - post it

Mark

there was no error. The function actually works. It doesn't work in "case 11: Rotate();". Meaning the push button doesn't trigger the action.
The other point is when I created different function with slightly different functionality, it worked great.

I think current_pin keeps getting incremened (by current_pin += dir), so the assignment to states[current_pin] in Rotate() overruns the array bounds after a few calls to Rotate(). Somehow you need to keep the value of current_pin within the range [ 0 .. PIN_COUNT ).

Some simple Serial debug prints will help you find your problem.
Blind debugging is hard.