@masher
I have tested your program without any change except adding few lines to blink L. Your program assigns correct value A/B/C/D/*/# to the variable age as you have wanted in your original post – “when they press a key other then an integer, the program will assign that number to the age.”. The break statement also works well.

Copy of your Codes:
#include <Keypad.h>
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] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup()
{
Serial.begin(9600);
Serial.print("Age: ");
pinMode(13, OUTPUT);
int i = 1;
char age = '0';
while (i == 1) { //change + to == in the light of Post#1
char customKey = customKeypad.getKey();
// if (customKey != 'A' && customKey != 'B' && customKey != 'C' && customKey != 'D' && customKey != '*' && customKey != '#' ) {
// Serial.print(customKey);
// }
if (customKey == 'A' || customKey == 'B' || customKey == 'C' || customKey == 'D' || customKey == '*' || customKey == '#')
{
age = customKey;
break;
}
}
Serial.println(age);
}
void loop()
{
digitalWrite(13, !digitalRead(13));
delay(1000);
}
@sterretje
I have tried/tested your codes; unfortunately, it does not show any result (except the message Age:) on the Serial Monitor. When the key A/B/C/D/*/# is pressed down, the break statement takes place.
#include <Keypad.h>
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] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup()
{
Serial.begin(9600);
Serial.print("Age: ");
pinMode(13, OUTPUT);
int i = 1;
char age = '0';
while (i == 1)
{ //change = to == in the light of Post#1
char customKey = customKeypad.getKey();
if (customKey == 'A' || customKey == 'B' || customKey == 'C' || customKey == 'D' || customKey == '*' || customKey == '#')
{
break;
}
else
{
age = customKey;
}
/*
// if (customKey != 'A' && customKey != 'B' && customKey != 'C' && customKey != 'D' && customKey != '*' && customKey != '#' ) {
// Serial.print(customKey);
// }
if (customKey == 'A' || customKey == 'B' || customKey == 'C' || customKey == 'D' || customKey == '*' || customKey == '#')
{
age = customKey;
break;
}
}
*/
}
Serial.println(age);
}
void loop()
{
digitalWrite(13, !digitalRead(13));
delay(1000);
}