Hi,
I am creating a menu system for my project and I am unable to break out of the IF statement to 'logout' of the program.
I have had to use the While loop so that the IF statement repeats waiting for an input from the keypad. The issue is with the 'Lock' option.
char customKey = customKeypad.getKey();
Serial.println(customKey);
if (customKey == '1'){
//Irrelevant code
}
else if (customKey == '2'){
//Irrelevant code
}
else if (customKey == '3'){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LOCKING...");
tone(buzzer, 1000);
delay(1000);
noTone(buzzer);
delay(4000);
lcd.clear();
digitalWrite(green_light_pin, LOW);
digitalWrite(red_light_pin, HIGH);
int passRight = 0;
clearData();
}
else{
}
}
The 'passRight' is the int for the While loop used.
The 'clearData()' is the void I want the code to run if the third option is selected.
Thanks in advance.
Please post your entire sketch, not just a snippet. What do you mean, "log out of the program"? There is no OS to go back to.
jamesdw333:
else if (customKey == '3'){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LOCKING...");
tone(buzzer, 1000);
delay(1000);
noTone(buzzer);
delay(4000);
lcd.clear();
digitalWrite(green_light_pin, LOW);
digitalWrite(red_light_pin, HIGH);
int passRight = 0;
clearData();
}
The 'passRight' is the int for the While loop used.
Can't be. You are creating a new LOCAL passRight inside that 'if' statement. That version of 'passRight' is not visible anywhere else, including any surrounding 'while' loop. Take out the 'int' so you use the existing 'passRight' instead of creating a new one.
I'm surprised the compiler didn't warn you that you were setting a variable that was never used. Be sure to set your warning level to ALL in Preferences.
johnwasser:
I'm surprised the compiler didn't warn you that you were setting a variable that was never used. Be sure to set your warning level to ALL in Preferences.
Thanks John, it was set 'None', hence why no warnings appeared whilst compiling. Using the messages I was able to solve the issue.
Many thanks!