Improper character assignment from membrane keypad input

Viewed 15

I'm trying to learn the use of an arduino keypad so i can use it in a future project. I'm have issue with the character assignment for the keys, and I can't figure it out, even using boilerplate code from a tutorial. Heres the code

// define the symbols on the buttons of the keypad
char keys[4][4] = {
 {'1', '2', '3', 'A'},
 {'4', '5', '6', 'B'},
 {'7', '8', '9', 'C'},
 {'*', '0', '#', 'D'}
};
byte rowPins[4] = {11, 10, 9, 8}; // connect to the row pinouts of the keypad
byte colPins[4] = {7, 6, 5, 4}; // connect to the column pinouts of the keypad
// initialize an instance of class Keypad
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, 4, 4 );
void setup() {
 Serial.begin(9600); // Initialize the serial port and set the baud rate to 9600
}
void loop() {
 // Get the character input
 char keyPressed = myKeypad.getKey();
 // If there is a character input, sent it to the serial port
 if (keyPressed) {
 Serial.println(keyPressed);
 }
}

Yes, all of my pins are hooked up properly. Here is the broken output i'm getting:

Input   output
1          1
2          1
3          3
A          1
4          4
5          4
6          6
B          4

This pattern repeats for the next two rows. I don't understand whats happenening here and it's breaking my brain. Please help!

0 Answers
Related