Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Keypad.h>
- #include <Wire.h>
- #include <DFPlayer_Mini_Mp3.h>
- #include "SoftwareSerial.h"
- SoftwareSerial mySerial(3, 12);
- const int buzzerPin = A3;
- # define Start_Byte 0x7E
- # define Version_Byte 0xFF
- # define Command_Length 0x06
- # define End_Byte 0xEF
- # define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
- # define ACTIVATED LOW
- boolean isPlaying = false;
- #define Password_Lenght 5 // Give enough room for six chars + NULL char
- char Data[Password_Lenght]; // 4 is the number of chars it can hold + the null char = 5
- char Master[Password_Lenght] = "1234";
- byte data_count = 0, master_count = 0;
- bool Pass_is_good;
- char customKey;
- 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'}
- };
- byte rowPins[ROWS] = {11, 10, 9, 8}; //connect to the row pinouts of the keypad
- byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
- Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad
- int activate = 0;
- void setup()
- {
- pinMode(buzzerPin, OUTPUT);
- pinMode(A0, OUTPUT);
- pinMode(A1, OUTPUT);
- digitalWrite(A0, 1);
- digitalWrite(A1, 1);
- pinMode(activate, INPUT);
- Serial.begin(9600);
- mySerial.begin (9600);
- delay(1000);
- //playFirst();
- //mp3_pause ();
- isPlaying = false;
- mp3_set_serial (mySerial); //set softwareSerial for DFPlayer-mini mp3 module
- mp3_set_volume (30);//18
- // Serial.println("Enter Password:");
- }
- void loop()
- {
- if (digitalRead(2)) {
- //Please dont remove headset:
- mp3_play (1);
- delay (25000);
- //Please enter password:
- mp3_play (2);
- delay (14000);
- while (1) {
- passwordChk();
- if (activate == 1) {
- break;
- }
- }
- if (activate == 1) {
- // Send reset to Arduino 1 digitalWrite();
- activate = 0;
- delay(3000);
- }
- }
- }// end of Loop
- void clearData()
- {
- while (data_count != 0)
- { // This can be used for any array size,
- Data[data_count--] = 0; //clear array for new data
- }
- return;
- }
- void passwordChk() {
- customKey = customKeypad.getKey();
- if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
- {
- Data[data_count] = customKey; // store char into data array
- Serial.print(Data[data_count]); // print char at said cursor
- data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
- buzz();
- }
- if (data_count == Password_Lenght - 1) // if the array index is equal to the number of expected chars, compare data to master
- {
- Serial.print("Password is ");
- if (!strcmp(Data, Master)) // equal to (strcmp(Data, Master) == 0)
- {
- // Pin is correct
- mp3_play (3);
- delay (19000);
- // payment of 50$ is accepted
- // Please put headset back
- activate = 1;
- digitalWrite(A0, 0);
- delay(1000);
- digitalWrite(A0, 1);
- digitalWrite(A1, 0);
- delay(1000);
- digitalWrite(A1, 1);
- Serial.println("Good");
- delay(1000);// added 1 second delay to make sure the password is completely shown on screen before it gets cleared.
- clearData();
- }
- else
- {
- // Pin is not Correct
- mp3_play (4);
- delay (15000);
- activate = 0;
- Serial.println("Bad");
- delay(1000);// added 1 second delay to make sure the password is completely shown on screen before it gets cleared.
- clearData();
- }
- }
- }
- void buzz() {
- digitalWrite(buzzerPin, 1);
- delay(100);
- digitalWrite(buzzerPin, 0);
- delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement