Simple Keypad Output

Hi All

For my understanding with the keypad library i have build up e simple 2 x 2 Button Matrix.
2 Rows, 2 Cols

"1" "2"
"3" "4"
Of course i read a lot about the coding of this.
Board is Arduino Leanardo

But for now when i press the first Button i get the first:"1"
when i hit the second i also see "1" in the Serial Mon.

I Press 3 ond get 4
i press 4 ond i get also 4.

now the code which i modyfied from a Example Code

Thanks a lot for help :wink:

////

#include <Keypad.h> //Bibliothek zum auslesen der Matrix Tastatur

//Definieren der Zeilen und Spalten.
//Wenn eine größere Tastatur verwendet wird,
//muss das hierdefiniert werden.
const byte COLS = 2;
const byte ROWS = 2;

//Definieren der Pins, über welche die Matrix Tastatur
//mit dem Microcontroller verbunden wurde.
const byte COL_PINS[COLS] = { 10, 11};
const byte ROW_PINS[ROWS] = { 8, 9};
//Da der Datentyp char nur ein Zeichen aufnehmen kann,
//verwende ich ab der Zahl 10 die Buchstaben A bis G.
const char KEYS[ROWS][COLS]={
  {'1','2'},
  {'3','4'},
};

//Initialisieren des KeyPad Objektes
Keypad myKeypad = Keypad(makeKeymap(KEYS), ROW_PINS, COL_PINS, ROWS, COLS);

void setup() {
//Begin der seriellen Kommunikation mit 9600 baud.
Serial.begin(9600);
}

void loop() {
//lesen ob eine Taste gedrückt wurde
char key = myKeypad.getKey();
//Wenn eine Taste gedrückt wurde,
//dann den Wert auf der seriellen Konsole
//Ausgeben.
if (key) {
  Serial.print("Die Taste ");
  Serial.print(key);
  Serial.println(" wurde gedrueckt");
}
}

Hi, your post is breaking forum rules. Please modify it and put in the code tags.

I can't see a problem with your code at the moment, so please post a schematic (drawn by hand on paper is ok) and some clear, bright photos so we can see each connection clearly.

For 4 buttons, I would just use 4 digitalReads, same number of pins, less to go wrong.

For my understanding with the keypad library i have build up e simple 2 x 2 Button Matrix.

I think the OP plans to expand the matrix, once it's working...

@mandax, if you have drawn your schematic accurately, then I see your error. Both S1 and S2 are connected from pin 08 to pin 10. Similar error with the other 2 buttons. Each button should connect to a unique pair of (row, column).

Thanks a lot. I will check that soon.

+1 karma for adding code tags.

I dont know what happen :-/
Now its working after rebuilding the test.

Thanks a lot anyway ond thanks for Karma :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.