And here is an 'AnalogKeypad' example sketch that might make you analog keypad work more like a matrix Keypad:
class AnalogKeypad
{
public:
AnalogKeypad(int ap, int keyCount, const char *keyChars, const int *keyValues) :
AnalogPin(ap), KeyCount(keyCount), KeyChars(keyChars), KeyValues(keyValues)
{
lastChar = 0;
};
char getKey()
{
int value = analogRead(AnalogPin);
if (value < KeyValues[0])
{
lastChar = 0;
return 0;
}
for (int i = 1; i <= KeyCount; i++)
{
if (value < KeyValues[i])
{
if (KeyChars[i] != lastChar)
{
lastChar = KeyChars[i];
return lastChar;
}
}
}
lastChar = 0;
return 0;
};
private:
const int AnalogPin;
const int KeyCount;
const char *KeyChars;
const int *KeyValues;
int lastChar;
};
const int KeypadPin = A0;
const int KeyCount = 16;
const int AnalogValues[KeyCount + 1] = {};
const char KeyChars[KeyCount + 1] = "123A456B789C*0#D";
AnalogKeypad keypad(KeypadPin, KeyCount, KeyChars, AnalogValues);
void setup()
{
Serial.begin(115200); /* Define baud rate for serial communication */
}
void loop()
{
char key = keypad.getKey();
if (key != 0)
Serial.print(key);
}