I have attached a 3x4 keypad to my Arduino Leonardo as an input method. Whenever I press the buttons, the majority of the keys work but specific ones don't. Here's my code, I've set it up to beep a piezo buzzer when it gets a keypress.
#include <Keypad.h>
int buzzerPin = 0;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {12, 13, 8, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {11, 7, 9}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT); //Set buzzerPin as output
keypad.addEventListener(keypadEvent); //Add an event listener for the KeyPad
}
void loop(){
char key = keypad.getKey();
}
void keypadEvent(KeypadEvent eKey) {
// When the KeyPad will be pressed, the results will appear on the serial monitor.
switch (keypad.getState()) {
case PRESSED:
Serial.print("Enter: ");
Serial.println(eKey);
beep(10);
delay(10);
break;
}
}
void beep(unsigned char delayms) { //creating function
tone(buzzerPin, 2000); //Setting pin to high
delay(delayms); //Delaying
noTone(buzzerPin); //Setting pin to LOW
delay(delayms); //Delaying
}
I based my rows/columns off of this pin-out: https://www.jaycar.com.au/12-key-numeric-keypad/p/SP0770, but I later found out some of the columns had to be swapped :P
Here's a diagram of what's happening: Diagram of working and not working keys
The keys in red do not work.
I wouldn't have posted this on stack exchange but it looks like an oddly specific pattern, and no matter what I changed, it didn't work.
(And yes, that is the exact keypad I bought from Jaycar)
Edit: I forgot to mention that I was using a prototype shield to plug the keypad into, but all pins are confirmed working on that.
1 Answer 1
A row against a row does not work, or a column against a colum.
That means there is a logical explanation. Row #2 is swapped with column #2.
Button 5 does work, because that still has a row against a column (but then the other way around).
5
actually works?