Xylitol icon

Electronic lock

Xylitol | PRO | 03/10/14 02:23:59 AM UTC | 0 ⭐ | 11930 👁️ | Never ⏰ | []
C Intermediate Language |

0 B

|

None

|

0 👍

/

0 👎

#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
 
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Password password = Password("1337");
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
// Define the Keymap
char keys[ROWS][COLS] = {
    {'1', '2', '3', 'A',},
    {'4', '5', '6', 'B',},
    {'7', '8', '9', 'C',},
    {'*', '0', ' ', 'D',}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {39, 38, 37, 36}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {43, 42, 41, 40}; //connect to the column pinouts of the keypad
const int buttonPin = 52;
int buttonState = 0;
 
// Create the Keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
 
#define ledPin 13
 
void setup() {
    lcd.begin(16, 2);
    pinMode(buttonPin, INPUT);
    pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, LOW); // sets the LED on
    Serial.begin(9600);
    keypad.addEventListener(keypadEvent); //add an event listener for this keypad
    keypad.setDebounceTime(250);
}
 
void loop() {
    keypad.getKey();
    buttonState = digitalRead(buttonPin);
 
    // check if the pushbutton is pressed.
    // if it is, the buttonState is HIGH:
    if (buttonState == HIGH) {
        // turn LED on:    
    } else {
        // turn LED off:
        lcd.clear();
        password.reset();
    }
}
 
//take care of some special events
void keypadEvent(KeypadEvent eKey) {
    switch (keypad.getState()) {
    case PRESSED:
        lcd.print(eKey);
        switch (eKey) {
        case ' ':
            guessPassword();
            break;
            lcd.setCursor(0, 1);
        default:
            password.append(eKey);
        }
    }
}
 
void guessPassword() {
    if (password.evaluate()) {
 
        digitalWrite(ledPin, HIGH);
        delay(2000);
        lcd.setCursor(0, 1);
        lcd.print("VALID PASSWORD");
        password.reset();
        delay(600);
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Welcome");
        delay(2000);
        lcd.clear();
        digitalWrite(ledPin, LOW);
    } else {
        digitalWrite(ledPin, LOW);
        lcd.setCursor(0, 1);
        lcd.print("INVALID PASSWORD");
        password.reset();
        delay(2000);
        lcd.clear();
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎