Hi Guys, I'm, still a bit of a noob when it comes to writing code, but i'm trying to learn!
For a project i need to attach a keypad. In the end it will need to change a boolean when i press a certain button, but for the experimenting i'm doing right now, i would be happy if i can serial print some teksts. With the great examples here, its no problem to get that to work.
The sketch below works fine, but for some reason the 3rd column does not work! I'm using the analog pins because i will need all digital pins for other purposes.
I already checked the keypad with a multimeter, and i can not find any issues with column 3. I also tried to connect column 3 to A7, but the problem remains the same.
I have no clue whats wrong. Some help would be very appreciated.
#include <Keypad.h>
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'A','B','C'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { A0, A1, A2, A3 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { A4, A5, A6 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define ledpin 13
void setup()
{
pinMode(ledpin,OUTPUT);
digitalWrite(ledpin, HIGH);
Serial.begin(9600);
}
void loop()
{
char key = kpd.getKey();
if(key) // Check for a valid key.
{
switch (key)
{
case '1':
Serial.println("test");
break;
case '2':
Serial.println("test 2");
break;
default:
Serial.println(key);
}
}
}