I am trying to have an Arduino Uno connected to an LCD, Keypad, and 3 LEDs for an escape room/ proposal. My goal is to have clues hidden around the property and have a map placed on the dining room table with LEDs underneath it, so when the correct password is inputted the next location on the map is revealed. However, when running the code it just flashes through the entire program rather than waiting for input to begin. Sorry in advance for the messy code, I was grasping at straws for a while trying to make it work.`Use code tags to format code for the forum
/*
Eli Turrentine
Escape room sequential keypad password system
Code based on
DroneBot Workshop 2020
https://dronebotworkshop.com
AND
https://www.circuitbasics.com/
*/
// Include Arduino Wire library for I2C
#include <Wire.h>
// Include LCD display library for I2C
#include <Adafruit_LiquidCrystal.h>
// Include Keypad library
#include <Keypad.h>
// Length of password + 1 for null character
#define Password_Length 5
// Character to hold password input
char Data[Password_Length];
// Password
char Master1[Password_Length] = "1111";
char Master2[Password_Length] = "2222";
char Master3[Password_Length] = "3333";
// Pin connected to lock relay input
int led1 = 13;
int led2 = 12;
int led3 = 11;
// Counter for character entries
byte data_count = 0;
// Character to hold key input
char customKey;
// Constants for row and column sizes
const byte ROWS = 4;
const byte COLS = 4;
// Array to represent keys on keypad
char hexaKeys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
// Connections to Arduino
byte rowPins[ROWS] = { 2, 3, 4, 5 };
byte colPins[COLS] = { 6, 7, 8, 9 };
// Create keypad object
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
// puzzle selection
bool checkPuzzle1 = false;
bool checkPuzzle2 = false;
bool checkPuzzle3 = false;
// Create LCD object
Adafruit_LiquidCrystal lcd_1(0);
void setup() {
// Setup LCD with backlight and initialize
lcd_1.begin(16, 2);
// Set led1, 2, 3 as OUTPUT pin
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop() {
// Initialize LCD and print
lcd_1.setCursor(0, 0);
lcd_1.print("Enter Password:");
// Look for keypress
customKey = customKeypad.getKey();
if (customKey) {
// Enter keypress into array and increment counter
Data[data_count] = customKey;
lcd_1.setCursor(data_count, 1);
lcd_1.print(Data[data_count]);
data_count++;
}
// See if we have reached the password length
if (data_count == Password_Length - 1) {
lcd_1.clear();
if (!strcmp(Data, Master1)) {
// Password is correct
lcd_1.print("Correct");
// Turn on relay for 5 seconds
digitalWrite(led1, HIGH);
delay(2500);
checkPuzzle1 = true;
//clear data
while (data_count != 0) {
Data[data_count--] = 0;
}
} else {
// Password is incorrect
lcd_1.print("Incorrect");
delay(1000);
while (data_count != 0) {
Data[data_count--] = 0;
}
}
lcd_1.setCursor(0, 0);
lcd_1.print("Enter Password:");
}
//puzzle 2
customKey = customKeypad.getKey();
// just print the pressed key
if ((customKey) && (checkPuzzle1 = true)) {
Data[data_count] = customKey;
lcd_1.setCursor(data_count, 1);
lcd_1.print(Data[data_count]);
data_count++;
}
if (data_count == Password_Length - 1) {
lcd_1.clear();
if (!strcmp(Data, Master2)) {
// password Correct
lcd_1.print("Correct");
digitalWrite(12, HIGH);
delay(2500);
while (data_count != 0) {
Data[data_count--] = 0;
}
checkPuzzle2 = true;
} else {
lcd_1.print("Incorrect");
delay(2000);
// Clear data and LCD display
lcd_1.clear();
while (data_count != 0) {
Data[data_count--] = 0;
}
}
lcd_1.setCursor(0, 0);
lcd_1.print("Enter Password:");
}
customKey = customKeypad.getKey();
// just print the pressed key
if ((customKey) && (checkPuzzle2 = true)) {
Data[data_count] = customKey;
lcd_1.setCursor(data_count, 1);
lcd_1.print(Data[data_count]);
delay(1);
data_count++;
}
if (data_count == Password_Length - 1) {
lcd_1.clear();
if (!strcmp(Data, Master2)) {
// password Correct
lcd_1.print("Correct");
digitalWrite(12, HIGH);
delay(2500);
while (data_count != 0) {
Data[data_count--] = 0;
}
checkPuzzle3 = true;
} else {
lcd_1.print("Incorrect");
delay(2000);
// Clear data and LCD display
lcd_1.clear();
while (data_count != 0) {
Data[data_count--] = 0;
}
}
}
if(checkPuzzle3=true){
lcd_1.clear();
lcd_1.print("CONGRATS");
}
}