martedì 13 gennaio 2015

Password inserita da Keypad.


La libreria Password permette di inserire una password da keypad.

      
      
      #include <Password.h> //http://www.arduino.cc/playground/uploads/Code/Password.zip
      #include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip
      #include <LiquidCrystal.h>
    
      Password password = Password( "1234" );
    
      LiquidCrystal lcd(8, 9, 10, 11, 12, 13);//pin ARDUINO MEGA 2560
    
      const byte RIGHE = 4; 
      const byte COLONNE = 4; 
      
      char keys[RIGHE][COLONNE] = {{'1','2','3','A'},
                                   {'4','5','6','B'},
                                   {'7','8','9','C'},
                                   {'F','0','E','D'}};
      
      byte rowPins[RIGHE]   = {14, 15, 16, 17}; //pin ARDUINO MEGA 2560
      byte colPins[COLONNE] = {18, 19, 20, 21};;//pin ARDUINO MEGA 2560

      Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, RIGHE, COLONNE );
      
      void setup()
           { lcd.begin(20, 4); 
             keypad.addEventListener(keypadEvent); }
      
     
      void loop(){
     
        keypad.getKey();
        lcd.setCursor(0, 0);
        lcd.print("Ins.Codice e press F");
   
      }//-------------Fine LOOP------------------------------
      
      void keypadEvent(KeypadEvent eKey){
           switch ( keypad.getState())
                  { case PRESSED:
                    switch ( eKey )
                           { case 'F': checkPassword(); 
                             break;
                            case 'E': password.reset();
                             break;
                            default: password.append(eKey);}}
      }//------------ FINE Void -------------------------------
      
      void checkPassword() {
           if ( password.evaluate())
              { lcd.setCursor(0, 1);
                lcd.print("Impianto Inserito   "); }
          else
              { lcd.setCursor(0, 1);
                lcd.print("Codice Errato        ");   }
     
      }//------------ FINE Void -------------------------------

Nessun commento:

Posta un commento