Hi, ich habe das Problem, dass mein 4x4 Numpad durchgehend die 1 in den Serial Monitor schickt.
Vielleicht kann mir ja jemand helfen.
Das ist mein Code
#include <Keypad.h>
// Definition für das Keypad von Elegoo
const byte ROWS = 4; // vier Zeilen
const byte COLS = 4; // vier Spalten
// Symbole auf den Tasten
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {35, 32, 33, 25}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {26, 27, 14, 12}; //connect to the column pinouts of the keypad
// Instanz von Keypad erzeugen, Keymap und Pins übergeben
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
}
void loop(){
// Gedrückte Taste abfragen
char customKey = customKeypad.getKey();
if (customKey) {
Serial.println(customKey);
}
else{
}
}
@ender1556
na dann zeig mal Bilder von deinem Aufbau. Jedes Kabel muss eindeutig sichtbar sein wo es drinnen steckt.
Gib an welchen Microcontroller du verwendest.
Dann einmal mit keypad laufen lassen und einmal ohne.
Beim ersten Versuch muss mindestens einmal ein PIN auf 1 gehen alle anderen 0 und beim zweiten Versuch - ohne Keypad - alle auf 0 bleiben.
const byte ROWS = 4; // vier Zeilen
const byte COLS = 4; // vier Spalten
byte rowPins[ROWS] = {35, 32, 33, 25}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {26, 27, 14, 12}; //connect to the column pinouts of the keypad
void setup()
{
Serial.begin(9600);
findKey();
}
void loop()
{
}
void allInput()
{
for (byte b = 0; b < 4; b++)
{
digitalWrite(rowPins[b], LOW);
digitalWrite(colPins[b], LOW);
pinMode(rowPins[b], INPUT);
pinMode(colPins[b], INPUT);
}
}
void findKey()
{
for (byte c = 0; c < 4; c++)
{
allInput();
pinMode(rowPins[c], OUTPUT);
digitalWrite(rowPins[c], HIGH);
Serial.print(F("Sendepin: "));
Serial.println(rowPins[c]);
for (byte d = 0; d < 4; d++)
{
Serial.print(colPins[d]);
Serial.print('=');
Serial.print(digitalRead(colPins[d]));
Serial.print('\t');
}
Serial.println();
}
Serial.println(F("Ende"));
}
So geht das bei mir auch nicht.
Ändere mal die Pins, so klappt das bei mir:
byte rowPins[ROWS] = {19, 18, 5, 17}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {16, 4, 0, 2}; //connect to the column pinouts of the keypad