#include <LiquidCrystal_I2C.h> // lcd library
#include <Keypad.h> // keypad library
#include <Wire.h> // I2C communication library
LiquidCrystal_I2C Lcd(0x27, 16, 2);
const byte rows = 4;
const byte cols = 4;
char keys[rows][cols] = {
{'1', '2', '3' , 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[rows] = {32, 33, 25, 26};
byte colPins[cols] = {27, 14, 12, 13};
Keypad keypad ( makeKeymap(keys), rowPins, colPins, rows, cols );
const String password = "1234"; // change your password here
String input_password;
int count = 0;
void setup() {
input_password.reserve(8);
Lcd.init();
Lcd.backlight();
Lcd.print("Enter YourPassword");
Lcd.setCursor(0, 1);
Serial.begin(9600);
}
void loop() {
char key = keypad.getKey();
if (key)
{
Serial.println(key);
if (key == '*')
{
if (count > 0)
{
count--;
input_password.remove(count);
Lcd.setCursor(count, 1);
Lcd.print (" ");
}
}
else if (key == '#')
{
if (password == input_password)
{
for (int i = 0; i < 3; i++) {
Lcd.setCursor(0, 0);
Lcd.clear();
Lcd.print("pass is correct");
delay(2000);
Lcd.setCursor(0, 0);
Lcd.clear();
delay(1000); }
Lcd.print("Enter Your pass");
Lcd.setCursor(0, 1);
}
else {
for (int i = 0; i < 3; i++) {
Lcd.setCursor(0, 0);
Lcd.clear();
Lcd.print("pass is Wrong");
delay(2000);
Lcd.setCursor(0, 0);
Lcd.clear();
delay(1000); }
Lcd.print("Enter Your Password");
Lcd.setCursor(0, 1);
}
input_password = "";
count = 0;
}
else
{
input_password += key;
Lcd.setCursor(count, 1);
Lcd.print(key);
count++;
Serial.print("count = ");
Serial.println(count);
}
Serial.println(input_password);
} // end of if(key)
} //end of void loop
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4