Advertisement
safwan092

Untitled

Aug 3rd, 2023
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. #include <Keypad.h>
  2.  
  3. #define esp32_pinD34_arduino_pin_10_data_0 10
  4. #define esp32_pinD35_arduino_pin_11_data_1 11
  5. #define ledPin 13
  6.  
  7. const byte ROWS = 4;
  8. const byte COLS = 4;
  9.  
  10. char hexaKeys[ROWS][COLS] = {
  11. {'1', '2', '3', 'A'},
  12. {'4', '5', '6', 'B'},
  13. {'7', '8', '9', 'C'},
  14. {'*', '0', '#', 'D'}
  15. };
  16.  
  17. byte rowPins[ROWS] = {9, 8, 7, 6};
  18. byte colPins[COLS] = {5, 4, 3, 2};
  19.  
  20. Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
  21.  
  22. String passcode = "1234";
  23.  
  24.  
  25. String userInputPassword = "";
  26. char customKey;
  27. void setup() {
  28. Serial.begin(9600);
  29. pinMode(ledPin, OUTPUT);
  30. pinMode(esp32_pinD34_arduino_pin_10_data_0, OUTPUT);
  31. pinMode(esp32_pinD35_arduino_pin_11_data_1, OUTPUT);
  32. send_to_ESP32_Null();
  33. customKeypad.addEventListener(keypadEvent);
  34. }
  35.  
  36. void loop() {
  37. customKey = customKeypad.getKey();
  38. if (customKey) {
  39. Serial.print(customKey);
  40. digitalWrite(ledPin, HIGH);
  41. userInputPassword += customKey;
  42. delay(100);
  43. digitalWrite(ledPin, LOW);
  44. }
  45. if (customKey == '#') {
  46. resetData();
  47. }
  48. }
  49.  
  50.  
  51. // Taking care of some special events.
  52. void keypadEvent(KeypadEvent key) {
  53. switch (customKeypad.getState()) {
  54. case PRESSED:
  55. if (key == '#') {
  56. Serial.println();
  57. Serial.println(userInputPassword);
  58. if (passcode == userInputPassword) {
  59. Serial.println("Password Correct !");
  60. digitalWrite(ledPin, HIGH);
  61. send_to_ESP32_11_Password_Correct();
  62. delay(1000);
  63. digitalWrite(ledPin, LOW);
  64. send_to_ESP32_Null();
  65. }
  66. else {
  67. Serial.println("Password False !!!!!");
  68. send_to_ESP32_10_Password_Wrong();
  69. delay(1000);
  70. flashingLED(3,200);
  71. send_to_ESP32_Null();
  72. }
  73. resetData();
  74. }
  75. break;
  76.  
  77. case RELEASED:
  78. if (key == '*') {
  79. resetData();
  80. }
  81. break;
  82.  
  83. case HOLD:
  84. if (key == '*') {
  85. resetData();
  86. }
  87. break;
  88. }
  89. }
  90.  
  91. void resetData() {
  92. userInputPassword = "";
  93. }
  94.  
  95. void send_to_ESP32_Null() {
  96. digitalWrite(esp32_pinD34_arduino_pin_10_data_0, LOW);
  97. digitalWrite(esp32_pinD35_arduino_pin_11_data_1, LOW);
  98. }
  99.  
  100. void send_to_ESP32_11_Password_Correct() {
  101. digitalWrite(esp32_pinD34_arduino_pin_10_data_0, HIGH);
  102. digitalWrite(esp32_pinD35_arduino_pin_11_data_1, HIGH);
  103. }
  104.  
  105. void send_to_ESP32_10_Password_Wrong() {
  106. digitalWrite(esp32_pinD34_arduino_pin_10_data_0, HIGH);
  107. digitalWrite(esp32_pinD35_arduino_pin_11_data_1, LOW);
  108. }
  109.  
  110. void flashingLED(int i, int T) {
  111. for (int j = 0; j < i; j++) {
  112. digitalWrite(ledPin, HIGH);
  113. delay(T);
  114. digitalWrite(ledPin, LOW);
  115. delay(T);
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement