Advertisement
safwan092

Untitled

Dec 15th, 2020
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.71 KB | None | 0 0
  1. #include <Keypad.h>
  2. #include <Wire.h>
  3. #include <DFPlayer_Mini_Mp3.h>
  4. #include "SoftwareSerial.h"
  5. SoftwareSerial mySerial(3, 12);
  6. const int buzzerPin = A3;
  7. # define Start_Byte 0x7E
  8. # define Version_Byte 0xFF
  9. # define Command_Length 0x06
  10. # define End_Byte 0xEF
  11. # define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
  12. # define ACTIVATED LOW
  13. boolean isPlaying = false;
  14.  
  15. #define Password_Lenght 5 // Give enough room for six chars + NULL char
  16. char Data[Password_Lenght]; // 4 is the number of chars it can hold + the null char = 5
  17. char Master[Password_Lenght] = "1234";
  18. byte data_count = 0, master_count = 0;
  19. bool Pass_is_good;
  20. char customKey;
  21. const byte ROWS = 4;
  22. const byte COLS = 4;
  23. char keys[ROWS][COLS] = {
  24.   {'1', '2', '3', 'A'},
  25.   {'4', '5', '6', 'B'},
  26.   {'7', '8', '9', 'C'},
  27.   {'*', '0', '#', 'D'}
  28. };
  29. byte rowPins[ROWS] = {11, 10, 9, 8}; //connect to the row pinouts of the keypad
  30. byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
  31. Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad
  32. int activate = 0;
  33.  
  34. void setup()
  35. {
  36.   pinMode(buzzerPin, OUTPUT);
  37.   pinMode(A0, OUTPUT);
  38.   pinMode(A1, OUTPUT);
  39.   digitalWrite(A0, 1);
  40.   digitalWrite(A1, 1);
  41.   pinMode(activate, INPUT);
  42.   Serial.begin(9600);
  43.   mySerial.begin (9600);
  44.   delay(1000);
  45.   //playFirst();
  46.   //mp3_pause ();
  47.   isPlaying = false;
  48.   mp3_set_serial (mySerial);  //set softwareSerial for DFPlayer-mini mp3 module
  49.   mp3_set_volume (30);//18
  50.  
  51.   // Serial.println("Enter Password:");
  52. }
  53.  
  54.  
  55. void loop()
  56. {
  57.   if (digitalRead(2)) {
  58.     //Please dont remove headset:
  59.     mp3_play (1);
  60.     delay (25000);
  61.     //Please enter password:
  62.     mp3_play (2);
  63.     delay (14000);
  64.     while (1) {
  65.       passwordChk();
  66.       if (activate == 1) {
  67.         break;
  68.       }
  69.     }
  70.     if (activate == 1) {
  71.       // Send reset to Arduino 1 digitalWrite();
  72.       activate = 0;
  73.       delay(3000);
  74.     }
  75.   }
  76.  
  77.  
  78. }// end of Loop
  79.  
  80. void clearData()
  81. {
  82.   while (data_count != 0)
  83.   { // This can be used for any array size,
  84.     Data[data_count--] = 0; //clear array for new data
  85.   }
  86.   return;
  87. }
  88.  
  89. void passwordChk() {
  90.   customKey = customKeypad.getKey();
  91.   if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
  92.   {
  93.     Data[data_count] = customKey; // store char into data array
  94.     Serial.print(Data[data_count]); // print char at said cursor
  95.     data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
  96.     buzz();
  97.   }
  98.  
  99.   if (data_count == Password_Lenght - 1) // if the array index is equal to the number of expected chars, compare data to master
  100.   {
  101.     Serial.print("Password is ");
  102.  
  103.     if (!strcmp(Data, Master)) // equal to (strcmp(Data, Master) == 0)
  104.     {
  105.       // Pin is correct
  106.       mp3_play (3);
  107.       delay (19000);
  108.       // payment of 50$ is accepted
  109.       // Please put headset back
  110.       activate = 1;
  111.       digitalWrite(A0, 0);
  112.       delay(1000);
  113.       digitalWrite(A0, 1);
  114.       digitalWrite(A1, 0);
  115.       delay(1000);
  116.       digitalWrite(A1, 1);
  117.       Serial.println("Good");
  118.       delay(1000);// added 1 second delay to make sure the password is completely shown on screen before it gets cleared.
  119.       clearData();
  120.     }
  121.     else
  122.     {
  123.       // Pin is not Correct
  124.       mp3_play (4);
  125.       delay (15000);
  126.       activate = 0;
  127.       Serial.println("Bad");
  128.       delay(1000);// added 1 second delay to make sure the password is completely shown on screen before it gets cleared.
  129.       clearData();
  130.     }
  131.  
  132.  
  133.   }
  134. }
  135.  
  136. void buzz() {
  137.   digitalWrite(buzzerPin, 1);
  138.   delay(100);
  139.   digitalWrite(buzzerPin, 0);
  140.   delay(50);
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement