/*
Demonstrate a basic matrix
Diodes : no
Ghosting : yes
https://wokwi.com/projects/400927180393138177
*/
#include <Keypad.h>
const byte ROWS = 3;
const byte COLS = 5;
char customKeys[ROWS][COLS] =
{
{ 'q','w','e','r','t'},
{ 'a','s','d','f','g'},
{ 'z','x','c','v','b'}
};
byte rowPins[ROWS] = {2,3,6};
byte colPins[COLS] = {4,5,7,8,9};
Keypad kpd = Keypad( makeKeymap(customKeys), rowPins ,colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
Serial.print("listening...");
}
void loop() {
if (kpd.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{
if ( kpd.key[i].stateChanged ) // Only find keys that have changed state.
{
switch (kpd.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED:
Serial.print(kpd.key[i].kchar);
}
}
}
}
} // End loop