// Include the necessary libraries for the ESP32 and the Arduino platform
#include <stdio.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <ESP32Servo.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int BARIS = 4;
const int KOLOM = 4;
char keys[BARIS][KOLOM] = { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'}
};
byte rowPins[BARIS] = {26, 27, 19, 18};
byte colPins[KOLOM] = {5, 4, 2, 15};
//Keypad customKeypad = Keypad(makeKeymap(Keys), rowPins, colPins, ROWS, COLS); //Masukkan info keypad pada library
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, BARIS, KOLOM);
char Key;
int number = 0;
int password = 1379;
int line=1;
int col=10;
/*
lcd.setCursor(0, 1);
lcd.clear();
*/
// Define the pin numbers for the pushbutton and the LED
#define LED_PIN 13
#define BUZZER_PIN 12
#define BTN_PIN 14
#define Servo 25
const int servoPin = 25;
Servo servo;
void setup() {
// Initialize the serial port for debugging purposes
Serial.begin(9600);
lcd.init();
lcd.setBacklight(HIGH);
// Set the pin modes for the pushbutton, LED, and buzzer
pinMode(BTN_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("Eenter Password:");
Key = keypad.getKey();
if (Key)
{
lcd.setCursor(line, col);
lcd.print(Key);
line++; // Move the cursor to the next line
lcd.setCursor(1,10);
Serial.print(Key);
delay(250);
}
// Check if the pushbutton has been pressed
if (digitalRead(BTN_PIN) == 0) {
// The pushbutton is pressed
// Turn on the LED and the buzzer
digitalWrite(LED_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH);
} else {
// The pushbutton is not pressed
// Turn off the LED and the buzzer
digitalWrite(LED_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
}
}