Keypad_Matrix
Keypad_Matrix copied to clipboard
Internal Pull-up resistors not enabled
I am having issues with a 2X2 layout with false triggers if my fingers touch any of the inputs, which made me suspect the pull-ups were not enabled. Looking into Keypad_Matrix.cpp, I believe line 131 should have a != as currently if you set pull-ups to TRUE, this line disables them.
// set each column to back to input
if (enablePullups_)
for (uint8_t i = 0; i < numCols_; i++)
pinMode (colPins_ [i], INPUT);
} // end Keypad_Matrix::~Keypad_Matrix`
Further down at line 158 they are enabled as expected
// set each column to input-pullup (optional)
if (enablePullups_)
for (uint8_t i = 0; i < numCols_; i++)
pinMode (colPins_ [i], INPUT_PULLUP);
} // end of Keypad_Matrix::begin
My initialisation is as follows
const byte ROWS = 2;
const byte COLS = 2;
char keyMap[ROWS][COLS] = {
{'a', 'b'},
{'c', 'd'}
};
byte colPins[COLS] = { 2, 3 }; // row pins
byte rowPins[ROWS] = { 5, 6 }; // col pins
// Create the keypad and map buttons with internall pullup resistors.
Keypad_Matrix kpd = Keypad_Matrix(makeKeymap(keyMap), rowPins, colPins, ROWS, COLS, true); // TRUE enables pull-ups
Line 131 is a comment
The INPUT_PULLUP lines are done in the begin function which you should be calling anyway before using it. See the README file.