Hi, so this is part 2 of my security system/ chicken coop door monitor project. Right now I'm just focusing on the security system part. I'm having difficulty displaying the password as its being typed. I definitely think it has something to do with the int Position = 0. What I want to do is have the password displayed as ***** on the LCD. The way I think I can do this is by increasing the values of Position by 1 each time a button is pressed. I don't think I implemented the Position part right (I probably messed up the password part too) and I'd really appreciate some help! If you have any questions about my code I'd be happy to clarify!
#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
Password password = Password( "1234" );
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {3, 5, 6, 7};
byte colPins[COLS] = {8, 9, 10};
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
void setup() {
lcd.begin(16, 2);
MainMenu();
Serial.begin(9600);
}
void loop() {
char myKey = myKeypad.getKey();
Serial.print("Pressed: ");
Serial.println(myKey);
if (myKey == '#') {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Enter Password");
int Position = 0;
if (myKey == '0' || myKey == '1' || myKey == '2' || myKey == '3' ||
myKey == '4' || myKey == '5' || myKey == '6' || myKey == '7' ||
myKey == '8' || myKey == '9' ) {
lcd.setCursor(Position, 1);
lcd.print('*');
++Position;
}
if (Position == 5) {
checkPassword();
password.append(myKey);
}
}
}
void checkPassword() {
if (password.evaluate()) {
Serial.println("Success");
} else {
Serial.println("Wrong");
password.reset();
}
}
void MainMenu () {
lcd.setCursor(0, 0);
lcd.print("* for Coop");
lcd.setCursor(0, 1);
lcd.print("# for Security");
}