#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <ESP32Servo.h>
// Cấu hình LCD (Địa chỉ 0x27 thường gặp, nếu không chạy hãy thử 0x3F)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Cấu hình Keypad
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'}
};
// Kết nối với ESP32 theo file JSON của bạn
byte rowPins[ROWS] = {35, 32, 33, 25};
byte colPins[COLS] = {26, 27, 19, 18};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Cấu hình Servo
Servo myservo;
const int servoPin = 17;
void setup() {
lcd.init();
lcd.backlight();
lcd.print("He thong san sang");
myservo.attach(servoPin);
myservo.write(0); // Vị trí ban đầu
}
void loop() {
char key = keypad.getKey();
if (key) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Da nhan phim: ");
lcd.print(key);
// Ví dụ: Nhấn phím '1' thì Servo quay
if (key == '1') {
myservo.write(90);
delay(1000);
myservo.write(0);
}
}
}