I added if statement that checks if # was pressed but it is not working. It is not removing characters i typed.
#include <Keypad.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int position = 0;
int line = 0;
char password[5] = "123D";
char input[5];
int typed = 0;
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] = { 9, 8, 7, 6 };
byte colPins[cols] = { 5, 4, 3, 2 };
Keypad customKeypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
int pos = 0;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.clear();
lcd.backlight();
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey && typed < 4) {
if(customKey == "#"){
lcd.clear();
}
typed++;
lcd.setCursor(position, line);
lcd.print(customKey);
input[position] = customKey;
position++;
}
//Checking
if (typed == 4 && strcmp(input, password) == 0) {
lcd.clear();
typed = 0;
position = 0;
Serial.println("CORRECT");
lcd.print("CORRECT");
} else if (typed == 4 && !(strcmp(input, password) == 0)) {
delay(2000);
lcd.clear();
typed = 0;
position = 0;
Serial.println("WRONG");
lcd.print(("WRONG"));
}
}