Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - /* The LCD circuit:
 - * LCD pin 1 to ground
 - * LCD pin 2 to 5V
 - * LCD RS pin 4 to digital pin 12
 - * LCD R/W pin 5 to ground
 - * LCD Enable pin 6 to digital pin 11
 - * LCD D4 pin 11 to digital pin 5
 - * LCD D5 pin 12 to digital pin 4
 - * LCD D6 pin 13 to digital pin 3
 - * LCD D7 pin 14 to digital pin 2
 - * LCD pin 15 to 5v with 220ohm resistor
 - * LCD pin 16 to ground
 - *
 - * 10K pot:
 - * one end to +5V and the other to ground
 - * wiper (middle pin) to LCD pin 3
 - */
 - #include <Password.h>
 - // include the library code:
 - #include <LiquidCrystal.h>
 - // include the keypad code:
 - #include <Keypad.h>
 - Password password = Password( "3570" );
 - const byte ROWS = 4; //four rows
 - const byte COLS = 3; //three columns
 - char keys[ROWS][COLS] = {
 - {'1','2','3'},
 - {'4','5','6'},
 - {'7','8','9'},
 - {'*','0','#'}
 - };
 - // keypad1 > pin13
 - // keypad2 > pin10
 - // keypad3 > pin9
 - // keypad4 > pin8
 - // keypad5 > pin7
 - // keypad6 > pin6
 - // keypad7 > pin0
 - byte rowPins[ROWS] = {10, 0, 6, 8}; //connect to the row pinouts of the keypad
 - byte colPins[COLS] = {9, 13, 7}; //connect to the column pinouts of the keypad
 - Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
 - // initialize the library with the numbers of the interface pins
 - LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
 - void setup() {
 - // set up the LCD's number of columns and rows:
 - lcd.begin(16, 2);
 - keypad.addEventListener(keypadEvent); //add an event listener for this keypad
 - keypad.setDebounceTime(100); //less bounce is more responsive
 - // Print a message to the LCD.
 - lcd.print("Enter code:");
 - }
 - void loop() {
 - // set the cursor to column 0, line 1
 - // line 0 is the first row, line 1 is the second row
 - lcd.setCursor(0, 1);
 - keypad.getKey();
 - // char key = keypad.getKey();
 - // if (key != NO_KEY){
 - // lcd.print(key); // print keypress to LCD
 - // }
 - }
 - //
 - //take care of some special events
 - void keypadEvent(KeypadEvent eKey){
 - switch (keypad.getState()){
 - case PRESSED:
 - lcd.print(eKey);
 - switch (eKey){
 - case '#': guessPassword(); break; // # is the 'enter' key
 - default:
 - password.append(eKey);
 - }
 - }
 - }
 - void guessPassword(){
 - if (password.evaluate()){
 - lcd.clear();
 - lcd.print("VALID PASSWORD"); //
 - password.reset(); //resets password after correct entry
 - delay(2000);
 - lcd.clear();
 - lcd.print("Welcome");
 - delay(3000);
 - lcd.clear();
 - lcd.setCursor(0, 0);
 - lcd.print("Enter code:");
 - }
 - else{
 - lcd.clear();
 - lcd.print("INVALID PASSWORD ");
 - password.reset(); //resets password after INCORRECT entry
 - delay(2000);
 - lcd.clear();
 - lcd.setCursor(0, 0);
 - lcd.print("Enter code:");
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment