switch default case runs from the beginning.

its a piece of program which is an Operating User Interface with TFT Screen and Keypad.

for the 10th keypad press i tried a switch case here
for if 10th press is X , Y or Z show their unique outputs.
if any other than these three ( X Y Z) i want to show " Invalid Press ".

but from the beginning  void testtext10(uint16_t color)     this function runs.
what can i do ?

            #define LCD_CS A3
            #define LCD_CD A2   
            #define LCD_WR A1   
            #define LCD_RD A0   

            #define LCD_RESET A4

            #define   BLACK           0x0000
            #define   BLUE            0x001F
            #define   RED             0xF800
            #define   GREEN           0x07E0
            #define   CYAN            0x07FF
            #define   MAGENTA         0xF81F
            #define   YELLOW          0xFFE0
            #define   WHITE           0xFFFF

            #include "TFTLCD.h"
            #include <Keypad.h>

            const byte ROWS = 5;
            const byte COLS = 4;
            char buff[16];
            long lastUpdate = 0;
            int x,i,e,k,xx;
            int j=11;

            TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

            char keys[ROWS][COLS] =
            {
              {'1','6','A','D'},
              {'2','7','B','E'},
              {'3','8','C','X'},
              {'4','9','Q','Y'},
              {'5','0','M','Z'},

            };

            byte rowPins[ROWS] = {40,39,38,37,36}; //connect to row pinouts
            byte colPins[COLS] = {32,33,34,35}; //connect to column pinouts

            Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

          //---------------------------------------------------------


          void setup(void)
            {
              Serial.begin(9600);
              Serial.println("      User Interface Menu Started!        ");
              tft.reset();
              tft.initDisplay();
            }

        void(* resetFunc) (void) = 0;

        //-------------------------------------------------------------


        void loop(void)
        {
             
           
              char key = keypad.getKey();
              if (key  != NO_KEY)

             {
                buff[i] = key;
                i = i+1;     
                x=x+4;
              }
           
              if((millis() - lastUpdate) > 700)                                                      // has it been >1 second since the last update?
             {
               
              if(i<10)
              {
              testtext(BLACK);
              lastUpdate = millis();     
              }
            }





            switch (buff[10])
        {
              case 'X':                                           // ok
              testtext5(BLACK);
              break;
             
              case 'Y':                                          // retry
              testtext3(BLACK) ;   
              break;
             
              case 'Z':                                          // reset
              testtext8(BLACK) ;
              break;
           
            default: testtext10(BLACK);              // invalid press
             
          }
        }

        //---------------------------------------------------------------
         
          void testtext(uint16_t color)                                                                   // 10 press in the beginning
               
        {
               if( i<11 )
             {
              tft.fillScreen(YELLOW);
              tft.setCursor(50, 20);
              tft.setTextColor(RED);
              tft.setTextSize(2);
              tft.println("EEEEEEE");
              tft.setCursor(50, 40);
              tft.setTextSize(2);
              tft.println("STUDENT ID");

              tft.setCursor(x, 75);
              tft.setTextSize(2);
              tft.print(buff);
             }
        }
         
         
        void testtext5(uint16_t color)                                                                            // PASSWORD INSERTING
          {
            if(i>10 && i<16)
             {
              tft.fillScreen(BLACK);
              tft.setCursor(50, 50);
              tft.setTextColor(RED);
              tft.setTextSize(2);
              tft.println("ENTER");
              tft.setCursor(50, 70);
              tft.setTextSize(2);
              tft.println("PASSWORD");

              tft.setCursor(x, 105);
              tft.setTextSize(2);
              tft.print( buff[11]);
              tft.print( buff[12]);
              tft.print( buff[13]);
              tft.print( buff[14]);
             }
        }
         
          void testtext10(uint16_t color)                                                                           // if right ?
            {
              tft.fillScreen(CYAN);
              tft.setCursor(180, 190);
              tft.setTextColor(RED);
              tft.setTextSize(2);
              tft.print(" INVALID PRESS ");
            }
           
           
           void testtext3(uint16_t color)                                                                         // if wrong
            {
              tft.drawRect(0, 0, tft.width(), tft.height(), WHITE);
              //tft.drawRect(tft.width() -0, tft.height() -0,240,320, CYAN);
              tft.fillRect(0, 0, tft.width(), tft.height(), WHITE);
              tft.setCursor(50, 80);
              tft.setTextColor(BLUE);
              tft.setTextSize(2);
              tft.print(" Enter Again ");
            }
           
           
            void testtext8(uint16_t color)                                                                             //  RESET
            {
             
             Serial.print(" RESET OK ");
              tft.drawRect(0, 0, tft.width(), tft.height(), WHITE);
              //tft.drawRect(tft.width() -0, tft.height() -0,240,320, CYAN);
              tft.fillRect(0, 0, tft.width(), tft.height(), WHITE);
              tft.setCursor(50, 80);
              tft.setTextColor(BLUE);
              tft.setTextSize(2);
              tft.print("RESET");     
            }

what can i do ?

Serial.print() the value in buff[10]. Make sure that it is what you think it is.

yes its an issue.
when i placed Serial.println(buff[10]); ,tft.print(buff[10]);
i see nothing in the serial window or TFT window.

i thought it is 10th press of the keypad. :frowning:

so if i want to achieve the purpose above i mentioned how can i move on ?

rajeetharan:
yes its an issue.
when i placed Serial.println(buff[10]); ,tft.print(buff[10]);
i see nothing in the serial window or TFT window.

i thought it is 10th press of the keypad. :frowning:

so if i want to achieve the purpose above i mentioned how can i move on ?

Where do you check to see if you've pressed 10 times?
I suggest an else{...} statement after if (i<10){...}