#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
lcd.init();
lcd.backlight();
// Print something
lcd.setCursor(1, 0);
lcd.print("Hello");
lcd.setCursor(1, 1);
lcd.print("Keypad Matriks");
delay(2000);
lcd.clear();
}
void loop(){
lcd.setCursor(0, 0);
lcd.print("Key pressed : ");
char key = keypad.getKey();
if (key){
Serial.println(key);
lcd.setCursor(14, 0);
lcd.println(key);
if (key == '1') {
tone(9, 500);
lcd.setCursor(6,1);
lcd.print("Do");
}
else if (key == '2') {
tone(9, 1000);
lcd.setCursor(6,1);
lcd.print("Re");
}
else
noTone(9);
}
}