/* (Straight Keys)
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
const int ROW_NUM = 4; // four rows
const int COLUMN_NUM = 4; // four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; // connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; // connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
LiquidCrystal_I2C lcd(0x27, 17, 2); // I2C address 0x27, 16 column and 2 rows
int cursorColumn = 0;
void setup(){
lcd.init(); // initialize the lcd
lcd.backlight();
}
void loop(){
char key = keypad.getKey();
lcd.setCursor(0, 0);
lcd.print(" Numeric Keypad");
if (key) {
lcd.setCursor(cursorColumn, 2); // move cursor to (cursorColumn, 0)
lcd.print(key); // print key at (cursorColumn, 0)
cursorColumn++; // move cursor to next position
if(cursorColumn == 17) { // if reaching limit, clear LCD
lcd.clear();
cursorColumn = 0;
}
}
}*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
// Initialize the I2C LCD
LiquidCrystal_I2C lcd(0x27, 20, 4); // Change 0x27 to your LCD's I2C address
// Define the Keypad
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; // Connect to the column pinouts of the keypad
// Create the Keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Numeric Keypad");
lcd.setCursor(0, 1);
lcd.print("Keypad Input:");
// Print an initial message on the LCD
lcd.setCursor(0, 2);
lcd.print("Press a key...");
}
void loop() {
char key = keypad.getKey();
if (key) {
// When a key is pressed, clear the current line and display the key
lcd.setCursor(0, 3);
lcd.print("Key Pressed: ");
lcd.print(key);
}
}