Go Down

Topic: Issue using a Keypad(4X4) to reset a password. (Read 252 times) previous topic - next topic

Ahmadiah

Even if the call get triggered by pressing a key in keypad ? do you have a better solution for this?
All I am trying to do is if a key is pressed go to ca() and if a certain key is pressed inside ca() go to fa().


Thank you again

sterretje

I don't have a keypad so can't test.

Below a revised version of your changPass function; note that this is just a rework of that function; if it will work or not I can't say.

Code: [Select]

void changPass() {
  static byte count = 0;
  char key;
  bool fPasswordSet = false;

  Serial.println(" ");
  Serial.println("Changing password?");
  Serial.println("Please type '1' for Yes or '0' for No to continue");

  // wait for user to conform or opt out
  while (1)
  {
    key = keypad.getKey();
    if (key == NO_KEY)
      continue;

    Serial.println("I'm here men");
    Serial.println(key);

    if (key == '0')
    {
      Serial.println("Don't worry! you will get back to password mode in bit");
      delay(1000);

      // user opted out; nothing else to do
      return;
    }
    else if (key == '1')
    {
      Serial.println("Tyep your new password:");
      Serial.println(" ");

      // user confirmed, break from while loop
      break;
    }
  }

  while (fPasswordSet == false)
  {
    // get new password
    while (count != 3)
    {
      key = keypad.getKey();
      if (key != NO_KEY)
      {
        chanPass[count++] = key;
      }
    }

    // reset count for next time that we want to change password
    count = 0;

    Serial.println(" You just changed your password");
    Serial.println("Are you stasified with the new password");
    Serial.println("'1' for yes and '0'for no?");

    // wait for user to confirm new password or to opt for retry
    while (1)
    {
      key = keypad.getKey();
      if (key == NO_KEY)
        continue;

      if (key == '0')
      {
        Serial.println("ok! lets' start over!");
      }

      else if (key == '1')
      {
        Serial.println("Give me a minute to save the new password");
        for (count = 0; count <= 3; count++)
        {
          UL[count] = chanPass[count];
        }
        count = 0;

        Serial.println("Done! Your new password is:");
        Serial.print( UL[0] );
        Serial.print( UL[1] );
        Serial.print( UL[2] );

        fPasswordSet = true;
      }
    }
  }
}
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Ahmadiah

Thanks man ! that's exactly what I end up doing.  I had to break the condition for "while" and "if" by incrementing a variable.  It did work perfect for me yesterday!

right know I am trying to do something extra resetting a password by holding "*" for two seconds and will take me to a new setup.  Every thing works except inside the setup routine when I includes/presses "*" it starts the setup routine again which really weird because to trigger the setup routine you need to hold "*" for two seconds.


here is the setup routine:

Code: [Select]

void changPass(){
   c = 0;  //an option if the user want to keep the new password or not.
   a = 0;  //for typing new password.
   b = 0;  //to break out from the first loop of changPass in case the desired work is done.
   k = 0;  //this is to make sure the k counting start from zero whenever enters in changPass().
  char key = keypad.getKey();
  
  Serial.println(" ");
  delay(500);
  Serial.println("Changing password?");
  delay(500);
  Serial.println("Please type '1' for Yes or '0' for No to continue");
  while (b != 1){
      
       while((key = keypad.getKey()) != NO_KEY){
              c = 0;
              //Serial.println(key);
              
              if (key != '0' && key != '1'){
                  Serial.println("Undefined key");
                  delay(500);
                  Serial.println("Please press '1' for yes or '0' for no");
                
              }
              
              else if (key == '0'){
                 Serial.println("NO");
                 Serial.println("Don't worry! you will get back to password mode in a bit");
                 delay(1000);
                 Serial.print(".");
                 delay(1000);
                 Serial.print(".");
                 delay(1000);
                 Serial.print(".");
                 delay(1000);
                 Serial.println(".");
                 b++;
                 Serial.println("********************");
                 Serial.println("Please enter password: ");
                
                  
               }
              else if (key == '1'){
                    Serial.println("YES");
                    delay(1000);
                    Serial.println("Tyep your new password (three characters):");
                    
                    while(a !=3 ){
                          while((key = keypad.getKey()) != NO_KEY) {
                          chanPass[a] = key;
                          Serial.print(key);
                          a++;
                          }
                    }
              }
                     if ( a >= 3 && c ==0){
                        Serial.println(" ");
                        Serial.println("You just changed your password!");
                        delay(1000);
                        Serial.println("Are you stasified with the new password");
                        delay(1000);
                        Serial.println("'1' for yes and '0'for no?");
                        
                        while(c < 1){
                                while((key = keypad.getKey()) != NO_KEY){
                                      if (key == '0'){
                                         Serial.println("NO");
                                         //Serial.println(key);
                                         delay(1000);
                                         Serial.println("ok! lets' start over!");
                                         c++;
                                         a = 0;
                                         Serial.println(" ");
                                         delay(500);
                                         Serial.println("Changing password?");
                                         delay(500);
                                         Serial.println("Please type '1' for Yes or '0' for No to continue");
                                        
                                      
                                       }
                                       else if (key == '1'){
                                              Serial.println("YES");
                                              delay(500);
                                              Serial.println("Give me a minute to save the new password");
                                              delay(1000);
                                              Serial.print(".");
                                              delay(1000);
                                              Serial.print(".");
                                              delay(1000);
                                              Serial.print(".");
                                              delay(1000);
                                              Serial.print(".");
                                              for(a=0; a<= 3; a++){
                                                passWord[a] = chanPass[a];
                                              }
                                              Serial.println(" ");
                                              Serial.println("Done! Your new password is:");
                                              Serial.print( passWord[0] );
                                              Serial.print( passWord[1] );
                                              Serial.println( passWord[2] );
                                              b++;
                                              Serial.println("********************");
                                              Serial.println("Please enter password: ");
                                            
                                        }
                                  
                                       c++;
                                    
                                }
                                
                         }
                     }
                        
            }
  
       }
  }

sterretje

I might not be so weird because I suspect the that event handler catching it when you release the '*' (even after a hold).

You will have to write a simple test sketch to so how the event handler behaves; you can leave loop empty

Code: [Select]

all your current declarations

void setup()
{
  all your current setup stuff
}

void loop()
{
}

//take care of some special events
void keypadEvent(KeypadEvent key) {
  switch (keypad.getState()) {
    case PRESSED:
      Serial.print(key); Serial.println(" pressed");
      break;
    case RELEASED:
      Serial.print(key); Serial.println(" released");
      }
    case HOLD:
      Serial.print(key); Serial.println(" held");
      break;
  }
}

That way you should be able to see what happens. I suspect that what you will see is (for a long press of '*')

Code: [Select]

* pressed
* held
* released
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Ahmadiah

I did solve it by doing the same as before. 

my next question, is it possible to do backspace and show it on serial monitor NOT LCD?

Thank you!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy