I'm using a Teensy 3.1 with the Keymap library to allow me to use a keyboard key matrix. Everything seems to be going smoothly with the sole exception of pin 13. I know pin 13 is tied to the LED and often written to for use as an indicator, so I suspect one of the libraries I'm using may be doing this and causing the interference I'm experiencing.
My code is almost identical to the code in the MultiKey example. The only difference is that I increased the key matrix to 8x16 to accommodate all of my keys. When I press just about any key on the keyboard I receive a pressed, released, and idle state. However, if the key is on pin 13 (column) I receive each of those states for every key on the corresponding row as well as one seemingly random key (not always the same key).
I tried increasing the setDebounceTime() to 250 which made the keyboard unresponsive to the point where it's hard to use, but even still just tapping any key on pin 13 results in 10-11 key presses.
I've included below my complete code, the key matrix, and an annotated version of the printout to demonstrate the behavior I'm experiencing. Any help/suggestions are greatly appreciated.
#include <Keypad.h>
#define KEY_FN MODIFIERKEY_RIGHT_GUI
const byte ROWS = 8;
const byte COLS = 16;
char keys[ROWS][COLS] = {
{ KEY_DELETE, KEY_EQUAL, KEY_F12, 0, MODIFIERKEY_RIGHT_ALT, 0, 0, 0, KEY_N, 0, KEY_B, KEY_F1, KEY_CAPS_LOCK, KEY_F8, 0, 0 },
{ KEY_PAGE_UP, KEY_MINUS, KEY_F9, KEY_BACKSLASH, 0, KEY_MENU, 0, 0, KEY_6, KEY_FN, KEY_5, KEY_F2, KEY_TILDE, KEY_F5, 0, 0 },
{ KEY_HOME, KEY_LEFT_BRACE, KEY_F10, 0, 0, 0, 0, KEY_RIGHT_BRACE, KEY_Y, 0, KEY_T, KEY_F3, KEY_TAB, KEY_F6, MODIFIERKEY_LEFT_CTRL, 0 },
{ KEY_END, KEY_SLASH, KEY_PERIOD, KEY_SPACE, 0, 0, 0, KEY_COMMA, KEY_M, 0, KEY_V, KEY_C, KEY_Z, KEY_X, 0, MODIFIERKEY_LEFT_SHIFT },
{ KEY_PAGE_DOWN, KEY_SEMICOLON, KEY_L, KEY_ENTER, 0, 0, 0, KEY_K, KEY_J, 0, KEY_F, KEY_D, KEY_A, KEY_S, MODIFIERKEY_RIGHT_CTRL, 0 },
{ KEY_RIGHT, KEY_0, KEY_9, KEY_DOWN, MODIFIERKEY_LEFT_ALT, 0, 0, KEY_8, KEY_7, 0, KEY_4, KEY_3, KEY_1, KEY_2, 0, 0 },
{ KEY_LEFT, KEY_P, KEY_O, KEY_UP, 0, 0, 0, KEY_I, KEY_U, 0, KEY_R, KEY_E, KEY_Q, KEY_W, 0, MODIFIERKEY_RIGHT_SHIFT },
{ KEY_INSERT, KEY_QUOTE, KEY_F11, KEY_BACKSPACE, 0, 0, MODIFIERKEY_LEFT_GUI, 0, KEY_H, 0, KEY_G, KEY_F4, KEY_ESC, KEY_F7, 0, 0 }
};
byte rowPins[ROWS] = {12, 15, 16, 18, 19, 21, 22, 23};
byte colPins[COLS] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 17, 20};
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
kpd.setDebounceTime(50);
}
unsigned long loopCount = 0;
unsigned long startTime = millis();
String msg = "";
void loop() {
loopCount++;
if ( (millis()-startTime)>1000 ) {
Serial.println(loopCount);
startTime = millis();
loopCount = 0;
}
// Fills kpd.key[ ] array with up-to 10 active keys.
// Returns true if there are ANY active keys.
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:
msg = " PRESSED.";
break;
case HOLD:
msg = " HOLD.";
break;
case RELEASED:
msg = " RELEASED.";
break;
case IDLE:
msg = " IDLE.";
}
Serial.print("Key ");
Serial.print(kpd.key[i].kchar, DEC);
Serial.println(msg);
}
}
}
}