//len
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int stage = 1;
const int LED = 13;
const byte ROWS = 4;
const byte COLS = 4;
char Keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
byte rowPins[ROWS] = { 9, 8, 7, 6 };
byte colPins[COLS] = { 5, 4, 3, 2 };
Keypad customKeypad = Keypad(makeKeymap(Keys), rowPins, colPins, ROWS, COLS);
String inputPassword = "";
String passwords[3] = { "1111", "2222", "3333" };
Adafruit_BMP085 bmp;
void setup() {
lcd.init();
lcd.backlight();
pinMode(LED, OUTPUT);
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("Kode Akses ");
lcd.print(stage);
lcd.print(": ");
char customKey = customKeypad.getKey();
if (customKey >= '0' && customKey <= '9') {
inputPassword += customKey;
lcd.setCursor(0, 1);
lcd.print(inputPassword);
}
if (customKey == '*') {
inputPassword = "";
lcd.clear();
}
if (customKey == '#') {
checkPassword();
}
}
void checkPassword() {
if (inputPassword == passwords[stage - 1]) {
lcd.setCursor(0, 2);
lcd.print("Kode Akses Benar");
delay(1000);
lcd.clear();
inputPassword = "";
stage++;
if (stage > 3) {
lcd.setCursor(0, 0);
lcd.print("Akses Diijinkan");
delay(5000);
lcd.clear();
monitorBMP180();
stage = 1;
}
} else {
lcd.setCursor(0, 2);
lcd.print("Kode Akses Salah");
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
inputPassword = "";
lcd.clear();
}
}
void monitorBMP180() {
while (true) {
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(bmp.readTemperature());
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Pressure: ");
lcd.print(bmp.readPressure());
lcd.print(" Pa");
lcd.setCursor(0, 2);
lcd.print("Altitude: ");
lcd.print(bmp.readAltitude());
lcd.print(" m");
delay(200); // Delay to allow the user to read the values
if (customKeypad.getKey() == '*') {
lcd.clear();
break;
}
}
}