#include <LiquidCrystal_I2C.h> //librari lcd i2c
#include <Keypad.h>
//kalau masih tdk tampil, ganti menjadi 0x3f(alamat i2c)
LiquidCrystal_I2C lcd(0x27,16,2);
const byte baris=4;
const byte kolom=4;
const int ledKedip=10;
char keys[baris][kolom]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte pinKolom[kolom]={5,4,3,2};
byte pinBaris[baris]={9,8,7,6};
Keypad customKeypad=Keypad(makeKeymap(keys),pinBaris,pinKolom,baris,kolom);
char stringAngka[17];
int indexKeypad = 0;
void setup() {
// put your setup code here, to run once:
lcd.init();
//lcd.begin(20,4);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.println("Welcome to LCD");
lcd.setCursor(0, 1);
lcd.println("Input keypad");
delay(1000);
lcd.clear();
pinMode(ledKedip, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
lcd.noBacklight(); //off backlight
lcd.setCursor(0, 0);
lcd.print("Banyak Kedip: ");
char customKey = customKeypad.getKey();
if (customKey) {
//Serial.println(customKey);
switch (customKey)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
stringAngka[indexKeypad++] = customKey;
lcd.setCursor(0, 1);
lcd.print(customKey);
break;
case '*'://reset
lcd.clear();
indexKeypad = 0;
break;
case '#':
stringAngka[indexKeypad] = 0;
//lcd.setCursor(0, 1);
int nilaiAngka = atoi(stringAngka);
kedip(nilaiAngka);
lcd.clear();
indexKeypad = 0;
break;
}
}
}
void kedip(int jml){
for(int i=1;i<=jml;i++){
lcd.noBacklight(); //off backlight
lcd.setCursor(8, 1);
lcd.print("Status: ON ");
digitalWrite(ledKedip, HIGH);
delay(500);
lcd.setCursor(8, 1);
lcd.print("Status: OF ");
digitalWrite(ledKedip, LOW);
delay(500);
}
}