#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
const int col = 16;
const int row = 2;
String Array;
LiquidCrystal_I2C lcd (0x27, col ,row);
int Percobaan=0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
#define lampu 2
byte rowPins[ROWS] = {32,33,25,26};
byte colPins[COLS] = {27,14,12,13};
//inisialisasi instansi keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
int posisition = 6;
void setup(){
Serial.begin(9600);
//
lcd.init();
lcd.backlight();
pinMode(lampu, OUTPUT);
}
void loop(){
char customKey = customKeypad.getKey();
lcd.setCursor(2,0);
lcd.print("MasukanToken");
if (customKey){
lcd.setCursor(posisition,1);
Array += customKey;
lcd.print(customKey);
// if (posisition <= 10){
posisition ++;
if (customKey == '#'){ // agar tidak lebih dari 8 digit
Array.remove(Array.length() - 1); //menngurangi array agar # dihapus
posisition = 20; // jika lebih dari 8 digit maka di pindahkan posisi nya
Percobaan++; //counter
Serial.print("Inputan [");
Serial.print(Percobaan);
Serial.print("] : ");
Serial.println(Array);
digitalWrite(LED_BUILTIN, HIGH);
if (Array== "1234"){ //input benar 1234
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Berhasil");
posisition = 6;
digitalWrite(lampu, HIGH);
delay(3000);
// == kondisi berhasil output sedang bermain sampai waktu selesai
}else{
lcd.clear();
lcd.setCursor(3,0);
lcd.print("InputSalah");
delay(3000);
posisition = 6;
Array = "";
}
}else if(customKey == 'D'){ //menghapus
posisition = 6;
lcd.clear();
Array = "";
digitalWrite(LED_BUILTIN, LOW );
}
// }
}
}