#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
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 = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String password = "1234";
String input = "";
int buzzer = 4;
int cursor = 0;
void setup() {
Serial.begin(115200);
lcd.init();
lcd.backlight();
pinMode(buzzer,OUTPUT);
lcd.setCursor(0,0);
lcd.print("Sifre Gir:");
}
void loop() {
char key = keypad.getKey();
if(key){
tone(buzzer,2000,80);
if(key == '#'){
lcd.clear();
if(input == password){
lcd.print("Dogru Sifre");
tone(buzzer,3000,200);
}
else{
lcd.print("Yanlis Sifre");
tone(buzzer,500,700);
}
delay(2000);
input="";
cursor=0;
lcd.clear();
lcd.print("Sifre Gir:");
}
else if(key == '*'){
if(input.length() > 0){
input.remove(input.length()-1);
cursor--;
lcd.setCursor(cursor,1);
lcd.print(" ");
lcd.setCursor(cursor,1);
}
}
else{
if(input.length() < 16){
input += key;
lcd.setCursor(cursor,1);
lcd.print("*");
cursor++;
}
}
}
}