I am working on a safe that unlocks when a certain password is input. It was working fine until I decided to add an LCD screen. Now when I type into the keypad, the 1-6, 0, A, B, and D. I do not need the * or # to appear. I have checked the wiring of the (in this case) 6-pin. This is the pin that (correct me if I'm wrong) controls the column 3rd from the top. I can provide pictures if needed. If you have any suggestions on my code that don't relate to the problem, they are greatly appreciated. Here is the code:
#include <Servo.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
Servo ServoMotor;
char password[4] = {'4', '2', '7', '\0'};
int position = 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] = { 8, 7, 6, 9 };
byte colPins[COLS] = { 5, 4, 3, 2 };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int RedpinLock = 12;
int GreenpinUnlock = 13;
LiquidCrystal lcd(10, A0, A1, A2, A3, A4);
void setup()
{
lcd.begin(16, 2);
pinMode(RedpinLock, OUTPUT);
pinMode(GreenpinUnlock, OUTPUT);
ServoMotor.attach(11);
LockedPosition(true);
}
void loop()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
if (key == '#')
{
position = 0;
ClearPassword();
UpdateDisplay();
}
else
{
if (key != '*')
{
password[position] = key;
position++;
}
if (position == 3)
{
CheckPassword();
}
UpdateDisplay();
}
}
delay(100);
}
void LockedPosition(int locked)
{
if (locked)
{
digitalWrite(RedpinLock, HIGH);
digitalWrite(GreenpinUnlock, LOW);
ServoMotor.write(11);
ClearPassword();
UpdateDisplay();
lcd.setCursor(0, 0);
lcd.print("Enter PSW:");
}
else
{
digitalWrite(RedpinLock, LOW);
digitalWrite(GreenpinUnlock, HIGH);
ServoMotor.write(90);
ClearPassword();
UpdateDisplay();
lcd.setCursor(0, 0);
lcd.print("Enjoy");
}
}
void UpdateDisplay()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter PSW:");
lcd.setCursor(0, 1);
lcd.print(password);
}
void ClearPassword()
{
for (int i = 0; i < 3; i++)
{
password[i] = ' ';
}
password[3] = '\0';
}
void CheckPassword()
{
if (strncmp(password, "427", 3) == 0)
{
LockedPosition(false);
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Incorrect");
delay(2000);
lcd.clear();
LockedPosition(true);
}
}
Thanks!