i’m doing a public locker, and this is my following plan for it:
the menu will ask you A for a new locker, and B to open an existing locker. i will be using a keypad, an eight
channel relay for each locker, and a 0x27 20x4 lcd screen.
next, After A or b it will ask you for a locker number
then, it processes if you put one or not. if it didn’t detect one, it will restart you. if it did, it
will say which locker you chose, and ask you to make a password, and it will open it once you put a 4 digit password.
i’ve been doing it well so far, until i realized my ClearData(); function doesn’t do what i intend it to do. can somebody find a way to clear the Data so I can reuse it? thanks! the code is below:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>//declares the library
#include <Keypad.h>
#define Password_Length 2//declares the amount of letters in the password-1
int i;
int Arelay = A0;
int otherArelay = A1;
char Data[Password_Length] = {0};
char Master[Password_Length];
byte data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] =
{7, 6, 5, 4};
byte colPins[COLS] =
{3, 2, 1, 0};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup()
{
lcd.init();
lcd.backlight();
pinMode(Arelay, OUTPUT);
pinMode(Arelay, LOW);
pinMode(otherArelay, OUTPUT);
pinMode(otherArelay, LOW);
for(i = 8; i < 14; i++)
{
pinMode(i, OUTPUT);
pinMode(i, LOW);
}
}
void loop()
{
lcd.home();
lcd.print("Welcome!");
lcd.setCursor(0,2);
lcd.print("A for new locker");
lcd.setCursor(0,3);
lcd.print("B to open locker");
customKey = customKeypad.getKey();//none of this has to do with the issue
if (customKey)
{
Data[data_count] = customKey;
data_count++;
if(!strcmp(Data, "A")) // if somebody put in A in the Keypad, do this
{
ClearData();
lcd.clear(); // clear the screen
lcd.print("Choose Locker Number");// write on the upper left corner of the lcd screen "Choose Locker Number"
delay(5000);// wait 5000 milliseconds
lcd.clear();
if(!strcmp(Data, "1"))
{
lcd.print("Choose Password for");
lcd.setCursor(0,1);
lcd.print("locker number:");
lcd.setCursor(0,3);
lcd.print(Data);
delay(7500);
}
else if(!strcmp(Data, "2"))
{
lcd.print("Choose Password for");
lcd.setCursor(0,1);
lcd.print("locker number:");
lcd.setCursor(0,3);
lcd.print(Data);
delay(7500);
}
else if(!strcmp(Data, "3"))
{
lcd.print("Choose Password for");
lcd.setCursor(0,1);
lcd.print("locker number:");
lcd.setCursor(0,3);
lcd.print(Data);
delay(7500);
}
else if(!strcmp(Data, "4"))
{
lcd.print("Choose Password for");
lcd.setCursor(0,1);
lcd.print("locker number:");
lcd.setCursor(0,3);
lcd.print(Data);
delay(7500);
}
else if(!strcmp(Data, "5"))
{
lcd.print("Choose Password for");
lcd.setCursor(0,1);
lcd.print("locker number:");
lcd.setCursor(0,3);
lcd.print(Data);
delay(7500);
}
else if(!strcmp(Data, "6"))
{
lcd.print("Choose Password for");
lcd.setCursor(0,1);
lcd.print("locker number:");
lcd.setCursor(0,3);
lcd.print(Data);
delay(7500);
lcd.clear(); //clears the screen again
lcd.print("PROCESSING...");
delay(7000);
lcd.clear();
}
else if(!strcmp(Data, "7"))
{
lcd.print("Choose Password for");
lcd.setCursor(0,1);
lcd.print("locker number:");
lcd.setCursor(0,3);
lcd.print(Data);
delay(7500);
lcd.clear(); //clears the screen again
lcd.print("PROCESSING...");
delay(7000);
lcd.clear();
}
else if(!strcmp(Data, "8"))
{
lcd.print("Choose Password for");
lcd.setCursor(0,1);
lcd.print("locker number:");
lcd.setCursor(0,3);
lcd.print(Data);
delay(7500);
lcd.clear(); //clears the screen again
lcd.print("PROCESSING...");
delay(7000);
lcd.clear();
}
else
{
lcd.clear();
lcd.print("Invalid Response:");
lcd.setCursor(0,1);
lcd.print(Data);
lcd.setCursor(0,2);
lcd.print("Please try again");
delay(2500);
lcd.clear();
ClearData();
}
}
else if(!strcmp(Data, "B")) // if somebody put in B in the keypad, do this:
{
ClearData();
lcd.clear();//clears the screen
lcd.print("Choose Locker Number");// prints the following on the lcd screen
delay(5000);// pauses the screen for 5000 milliseconds
lcd.clear();//clears the screen
}
else// otherwise:
{
lcd.clear();//clear the screen
lcd.print("Invalid Answer:");// write the following on the lcd
lcd.setCursor(0,1);//set the cursor to the next line
lcd.print(Data);// prints what the person put on the keypad
lcd.setCursor(0,2);//sets the cursor to the next line
lcd.print("please try again");// writes that on the lcd
delay(2500);// pauses that screen 2500 milliseconds
lcd.clear();//clears the screen
ClearData();
}
ClearData();
}
}
void ClearData()//declares the function
{
while(data_count !=0)//basically the rest of this deletes the data of the code, has nothing to do with the issue
{
Data[data_count--] = 0;
}
return;
}