#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
LiquidCrystal_I2C lcd(0x27,16,2);
byte rowPins[ROWS] = {11, 10, 9, 8};
byte colPins[COLS] = {7, 6, 5, 4};
byte pinRelay = 2;
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
//tuliskan program persiapan disini
//contoh program dapat dilihat pada file Tutorial mulai halaman 139
lcd.begin(16,2);
lcd.clear();
lcd.backlight();
pinMode(pinRelay, OUTPUT);
}
int pos = 0;
void loop() {
//tuliskan program yang menampilkan setiap huruf yang ditekan di keypad pada layar LCD
//tambahkan program jika ditekan tombol * maka lampu hidup dan # untuk mematikan lampu
//silahkan menambahkan kreatifitas/variasi lain
char keyPress = customKeypad.getKey();
if (keyPress) {
if (keyPress=='C') {
if (pos>0) {
pos--;
lcd.setCursor(pos,0);
lcd.print(' ');
lcd.setCursor(pos,0);
}
} else {
lcd.print(keyPress);
pos++;
}
if(keyPress=='*') {
digitalWrite(pinRelay,HIGH);
}
if(keyPress=='#') {
digitalWrite(pinRelay,LOW);
}
}
}