Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //libarys
- #include <LiquidCrystal.h>
- #include <Keypad.h>
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(4, 5, 6, 7, 8, 9);
- const byte ROWS = 4; //four rows
- const byte COLS = 4; //four columns
- //define the cymbols on the buttons of the keypads
- char hexaKeys[ROWS][COLS] = {
- {'1', '2', '3', 'A'},
- {'4', '5', '6', 'B'},
- {'7', '8', '9', 'C'},
- {'*', '0', '#', 'D'}
- };
- byte rowPins[ROWS] = {10, 11, 12, 13}; //connect to the row pinouts of the keypad
- byte colPins[COLS] = {A3, A2, A1, A0}; //connect to the column pinouts of the keypad
- int digits, password;
- bool PasswordIsVis = false;
- Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
- void setup() {
- lcd.begin(16, 2);
- pinMode(2, OUTPUT);
- digitalWrite(2, LOW);
- Serial.begin(9600);
- }
- void passwordcon(char keys) {
- int key = keys - '0';
- Serial.println(key);
- Serial.println(digits);
- int setpassword = 1003;
- if (digits == 1) {
- password = 1;
- }
- password = password + key * pow(10, 4 - digits);
- if (digits == 4 && password == setpassword) {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Correct Password!");
- digitalWrite(2, HIGH);
- delay(1000);
- digitalWrite(2, LOW);
- password = 0;
- digits = 0;
- }
- else if (digits == 4 && password != setpassword) {
- digits = 0;
- password = 0;
- lcd.setCursor(0, 0);
- lcd.clear();
- lcd.print("Wrong Password!");
- delay(1000 * 4);
- lcd.clear();
- }
- }
- void loop() {
- lcd.setCursor(0, 0);
- lcd.print("Enter Password: ");
- // print the number of seconds since reset:
- char customKey = customKeypad.getKey();
- if (customKey) {
- lcd.setCursor(0, 1);
- digits++;
- passwordcon(customKey);
- if (PasswordIsVis == false) {
- for (int i = digits; i > 0; i--) {
- lcd.print("*");
- }
- }
- else {
- lcd.print(password);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement