I'm trying to use an Arduino UNO to read which button I push on a 4x4 matrix keypad, then output it on an LCD screen. However, I can't get the Arduino to read which button is pressed. Can someone please help me? I've started over with the code from the keypad tutorial with no luck and haven't found a similar example.
When I upload the code to the arduino controller, there are 5 volts on the row pins of the keypad and 0-0.5 volts on the column pins. Pushing the buttons will cause 5 volts to show up on the individual pins of the corresponding buttons, but the arduino still doesn't recognize it to output it to the LCD screen. Do I need to hold the button? or push it repeatedly for the getkey() function to work? do I need to put a delay in somewhere?
Please help...
Here is my code: (I've swapped keypads and reduce the matrix size in an attempt to do some troubleshooting)
#include <Key.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const byte ROWS = 2; //four rows
const byte COLS = 2; //three columns
char keys[ROWS][COLS] = {
{'1','2'},
{'7',''},
// {'7','8','9'},
//{'#','0',''}
};
byte rowPins[ROWS] = {6, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 10}; //connect to the column pinouts of the keypad
//Create the Keypad
Keypad slcKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("buttons");
}
void loop(){
char key2 = slcKeypad.getKey();
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
lcd.print(key2);
if (key2 == NO_KEY){
lcd.print("agitated");
}
}