// Does not recognize simultaneous buttons
#include <Keypad.h>
const byte rows = 4, cols = 4;
byte rowPins[rows] = {5, 6, 7, 8};
byte colPins[cols] = {12, 11, 10, 9};
const int numRows = sizeof(rowPins) / sizeof(rowPins[0]);
const int numCols = sizeof(colPins) / sizeof(colPins[0]);
// Define the keymap
char keys[numRows][numCols] = {
{'0', '1', '2', '3'},
{'4', '5', '6', '7'},
{'8', '9', 'A', 'B'},
{'C', 'D', 'E', 'F'}
};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, numRows, numCols);
void setup() {
Serial.begin(115200);
for (int i = 0; i < numRows; i++) {
pinMode(rowPins[i], INPUT_PULLUP);
}
for (int i = 0; i < numCols; i++) {
pinMode(colPins[i], OUTPUT);
digitalWrite(colPins[i], HIGH); // set columns to HIGH initially
}
}
void loop() {
char button = keypad.getKey();
if (button) {
Serial.print(button);
}
}
// https://www.youtube.com/watch?v=Z7Sc4MJ8RPMCOLS
ROWS
0
1
2
3
4
8
C
0