Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Keypad.h>
- #define esp32_pinD34_arduino_pin_10_data_0 10
- #define esp32_pinD35_arduino_pin_11_data_1 11
- #define ledPin 13
- const byte ROWS = 4;
- const byte COLS = 4;
- char hexaKeys[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(hexaKeys), rowPins, colPins, ROWS, COLS);
- String passcode = "1234";
- String userInputPassword = "";
- char customKey;
- void setup() {
- Serial.begin(9600);
- pinMode(ledPin, OUTPUT);
- pinMode(esp32_pinD34_arduino_pin_10_data_0, OUTPUT);
- pinMode(esp32_pinD35_arduino_pin_11_data_1, OUTPUT);
- send_to_ESP32_Null();
- customKeypad.addEventListener(keypadEvent);
- }
- void loop() {
- customKey = customKeypad.getKey();
- if (customKey) {
- Serial.print(customKey);
- digitalWrite(ledPin, HIGH);
- userInputPassword += customKey;
- delay(100);
- digitalWrite(ledPin, LOW);
- }
- if (customKey == '#') {
- resetData();
- }
- }
- // Taking care of some special events.
- void keypadEvent(KeypadEvent key) {
- switch (customKeypad.getState()) {
- case PRESSED:
- if (key == '#') {
- Serial.println();
- Serial.println(userInputPassword);
- if (passcode == userInputPassword) {
- Serial.println("Password Correct !");
- digitalWrite(ledPin, HIGH);
- send_to_ESP32_11_Password_Correct();
- delay(1000);
- digitalWrite(ledPin, LOW);
- send_to_ESP32_Null();
- }
- else {
- Serial.println("Password False !!!!!");
- send_to_ESP32_10_Password_Wrong();
- delay(1000);
- flashingLED(3,200);
- send_to_ESP32_Null();
- }
- resetData();
- }
- break;
- case RELEASED:
- if (key == '*') {
- resetData();
- }
- break;
- case HOLD:
- if (key == '*') {
- resetData();
- }
- break;
- }
- }
- void resetData() {
- userInputPassword = "";
- }
- void send_to_ESP32_Null() {
- digitalWrite(esp32_pinD34_arduino_pin_10_data_0, LOW);
- digitalWrite(esp32_pinD35_arduino_pin_11_data_1, LOW);
- }
- void send_to_ESP32_11_Password_Correct() {
- digitalWrite(esp32_pinD34_arduino_pin_10_data_0, HIGH);
- digitalWrite(esp32_pinD35_arduino_pin_11_data_1, HIGH);
- }
- void send_to_ESP32_10_Password_Wrong() {
- digitalWrite(esp32_pinD34_arduino_pin_10_data_0, HIGH);
- digitalWrite(esp32_pinD35_arduino_pin_11_data_1, LOW);
- }
- void flashingLED(int i, int T) {
- for (int j = 0; j < i; j++) {
- digitalWrite(ledPin, HIGH);
- delay(T);
- digitalWrite(ledPin, LOW);
- delay(T);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement