title: Arduino software (Exiting from one loop and get ready for another
body: <p>I am working on a keypad password lock system based on Arduino UNO. I have used the password library from Arduino's website. </p>
  
  <p>What I am trying to accomplish is to set two passwords namely pass1 and pass 2.</p>
  
  <p>The condition is that this circuit is attached to a gate, if user 1 lets say knows pass1, after entering the pass the gate will unlock for 10 seconds and the pass1 becomes invalid i.e. can not be used in future. However if user 2 comes and knows pass2, after entering the pass2, the gate will open for 10 seconds and then pass2 becomes invalid, in a nutshell a password can be used only once. I am attaching the code below. The problem with this code is that when pass1 is executed, the system does not take pass2 until unless the system is reset.</p>
  
  <pre><code>  #include &lt;Password.h&gt;
  
    #include &lt;LiquidCrystal.h&gt;
    #include &lt;Password.h&gt; 
    #include &lt;Keypad.h&gt; 
    LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
    Password password1 = Password( "1234" );
    Password password2 = Password( "4567" );
    int ledpin = A5;
    int a=0;
    const byte ROWS = 4; // Four rows
    const byte COLS = 4; // columns
  
     char keys[ROWS][COLS] = {
     {'1','2','3','A'},
     {'4','5','6','B'},
     {'7','8','9','C'},
     {'*','0','#','D'}
     };
  
    byte rowPins[ROWS] = { A0, A1, A2, A3 };/
    byte colPins[COLS] = { 8, 9, 10, 11 };
  
  
  
    Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS   );
  
    void setup(){
  
    lcd.begin(16,2);
    keypad.addEventListener(keypadEvent); //add an event listener for this   keypad
      }
  
      void loop(){
       keypad.getKey();
      }
  
  
      void keypadEvent(KeypadEvent eKey){
      switch (keypad.getState()){
      case PRESSED:
  
      lcd.println(eKey);
      switch (eKey){
      case '*':
      checkPassword();
      break;
      case '#':
      password1.reset();
  
      password2.reset();
      break;
      default:
      password1.append(eKey);
      password2.append(eKey);
  
      }       return ; 
      }
      }
  
  
      void checkPassword(){
  
      if (password1.evaluate()){
      lcd.setCursor(0,1);
      lcd.println("code1 OK");
      delay (2000);
      digitalWrite(ledpin, HIGH);
      delay(10000);
      digitalWrite(ledpin,LOW);
      password1.append('1');
      lcd.clear();
  
      return;
  
  
      }else if (password2.evaluate()){ 
  
      lcd.setCursor(0,1);
      lcd.println("code2 OK");
      delay (2000);
      digitalWrite(ledpin,HIGH);
      delay(10000);
      digitalWrite(ledpin,LOW);
      password2.append('2');
      lcd.clear();
      return; 
  
  
  
  
     }else {
     lcd.setCursor(0,1);
     lcd.println("Wrong");
     delay(2000);
     lcd.clear();
     lcd.print("Wait for 5 Sec");
     delay(5000);
     lcd.clear();
     return;
  
  
  
    //add code to run if it did not work
    }return;
    }
  </code></pre>