Hi everyone, I am having trouble with a loop in my code that won't exit when I expect it to. It's supposed to take each keypad press, display it on an LCD, save it into a x-digit number for x presses, and exit the loop to the next part when the * key is pressed. I think either I'm doing something wrong with the type of data for the variables being compared, or else my understanding of while loops is wrong. Anyways here's the relevant section of code:
char asciiNum2 = 69;
String paidNumAscii = "";
char star = 42;
while (asciiNum2 != star){
char asciiNum2 = myKeypad.waitForKey();
lcd.print(asciiNum2);
paidNumAscii += asciiNum2;
Serial.println(asciiNum2);
Serial.println(star);
Serial.println(paidNumAscii);
}
The idea is that it will see asciiNum2 == star when * is pressed and it will exit the loop. The numbers print on the LCD fine but its prints the * and doesn't move to the next command. This is the serial output when I type in 7 0 * on the keypad:
7
*
7
0
*
70
*
*
70*
In the last group of 3 we can see asciiNum2 and star both come out as *. I'm not too experienced so any help or advice is much appreciated!