#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ROWS = 4; // Jumlah baris keypad
const byte COLS = 4; // Jumlah kolom keypad
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; // Ke pin baris keypad
byte colPins[COLS] = {13, 12, 11, 10}; // Ke pin kolom keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
unsigned long countdownStartTime = 0;
const unsigned long countdownDuration = 10000; // 10 seconds
bool countdownActive = true;
void setup() {
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pilih 1-2");
countdownStartTime = millis();
}
void loop() {
if (countdownActive) {
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - countdownStartTime;
if (elapsedTime >= countdownDuration) {
countdownActive = false;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Waktu Habis");
} else {
int remainingTime = (countdownDuration - elapsedTime) / 1000;
lcd.setCursor(0, 1);
lcd.print("Waktu: " + String(remainingTime) + " detik");
char key = keypad.getKey();
if (key == '1') {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Selamat Datang");
countdownActive = false;
} else if (key == '2') {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Wellcome");
countdownActive = false;
}
}
}
}