I'm making a keyboard, and wanted to start small by making a 2 x 3 keypad just to test if I can get that to work.
In a separate project I got all HID stuff working, including media keys, etc.
Everything seems to work as expected, except for the last column (on both rows).
One thing to note is that I have the arduino just sitting on some connector pins on the breadboard, but moving it around doesn't change anything, but that does sometimes cause the other columns to not work.
Here's the code:
#include <Keypad.h>
const byte ROWS = 2; // Four rows
const byte COLS = 3; // Three columns
char keys[ROWS][COLS] = {
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = { 3, 2 };
byte colPins[COLS] = { 6, 5, 4 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(9600);
while (!Serial) ;
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
}
void loop() {
char keyA = kpd.getKey();
for (int i = 0; i < 6; i++) {
PrintKey(i);
}
Serial.println("---------------------------------");
delay(400);
if(keyA)
{
switch (keyA)
{
case '*':
digitalWrite(LED_BUILTIN, LOW);
break;
case '#':
digitalWrite(LED_BUILTIN, HIGH);
break;
default:
Serial.println(keyA);
}
}
}
void PrintKey(int i) {
Serial.print(i);
Serial.print(" : ");
switch(kpd.key[i].kstate) {
case IDLE:
Serial.println("IDLE");
break;
case PRESSED:
Serial.print(kpd.key[i].kchar);
Serial.println(" PRESSED");
break;
case HOLD:
Serial.print(kpd.key[i].kchar);
Serial.println(" HOLD");
break;
case RELEASED:
Serial.print(kpd.key[i].kchar);
Serial.println(" RELEASED");
break;
default:
Serial.println(" UNKNOWN");
}
}
Is something wrong with how I've wired everything up or the code, or is it a bad connection somewhere?