// Include the Keypad library
#include <Keypad.h>
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(3, 4); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
// Constants for row and column sizes
const byte ROWS = 4;
const byte COLS = 4;
// Array to represent keys on keypad
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', '4'},
{'5', '6', '7', '8'},
{'9', 'a', 'b', 'c'},
{'d', 'e', 'M', '0'}
};
// Connections to Arduino
byte rowPins[ROWS] = {12, 11, 10, 9};
byte colPins[COLS] = {8, 7, 6, 5};
// Create keypad object
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
int catCount=0;
void setup() {
// Setup serial monitor
Serial.begin(9600);
mySoftwareSerial.begin(9600);
myDFPlayer.begin(mySoftwareSerial); //Use softwareSerial to communicate with mp3.
myDFPlayer.volume(30); //Set volume value. From 0 to 30
// keypad.addEventListener(keypadEvent); // Add an event listener.
customKeypad.setHoldTime(500); // Default is 1000mS
customKeypad.setDebounceTime(250); // Default is 50mS
}
void loop() {
// Get key value if pressed
char customKey = customKeypad.getKey();
if (customKey=='M')
{
catCount=1;
Serial.println("CAT pressed");
cat1();
}
}
void cat1()
{
Serial.println("CAT_1");
myDFPlayer.playFolder(15,1);
delay(100);
char customKey;
while(true)
{
customKey=customKeypad.getKey();
if(customKey=='M')
{++catCount;
if(catCount==4)
catCount=1;
cat2();
}
else if(customKey)
{
if(customKey=='1')
{
myDFPlayer.playFolder(1,1);
delay(100);
Serial.println("TVM_1");
customKey=0;
}
else if(customKey=='2')
{
myDFPlayer.playFolder(1,2);
delay(100);
Serial.println("KLM_1");
customKey=0;
}
else if(customKey=='3')
{
myDFPlayer.playFolder(1,3);
delay(100);
Serial.println("PTM_1");
customKey=0;
}
else if(customKey=='4')
{
myDFPlayer.playFolder(1,4);
delay(100);
Serial.println("ALP_1");
customKey=0;
}
else if(customKey=='5')
{
myDFPlayer.playFolder(1,5);
delay(100);
Serial.println("KTM_1");
customKey=0;
}
else if(customKey=='6')
{
myDFPlayer.playFolder(1,6);
delay(100);
Serial.println("IDK_1");
customKey=0;
}
else if(customKey=='7')
{
myDFPlayer.playFolder(1,7);
delay(100);
Serial.println("EKM_1");
customKey=0;
}
else if(customKey=='8')
{
myDFPlayer.playFolder(1,8);
delay(100);
Serial.println("THR_1");
customKey=0;
}
else if(customKey=='9')
{
myDFPlayer.playFolder(1,9);
delay(100);
Serial.println("PKD_1");
customKey=0;
}
else if(customKey=='a')
{
myDFPlayer.playFolder(1,10);
delay(100);
Serial.println("MLP_1");
customKey=0;
}
else if(customKey=='b')
{
myDFPlayer.playFolder(1,11);
delay(100);
Serial.println("KZD_1");
customKey=0;
}
else if(customKey=='c')
{
myDFPlayer.playFolder(1,12);
delay(100);
Serial.println("WYD_1");
customKey=0;
}
else if(customKey=='d')
{
myDFPlayer.playFolder(1,13);
delay(100);
Serial.println("KNR_1");
customKey=0;
}
else if(customKey=='e')
{
myDFPlayer.playFolder(1,14);
delay(100);
Serial.println("KKD_1");
customKey=0;
}
}}}
void cat2()
{
myDFPlayer.playFolder(15,2);
delay(100);
Serial.println("CAT_2");
char customKey;
while(true)
{
customKey=customKeypad.getKey();
if(customKey=='M')
{++catCount;
if(catCount==4)
catCount=1;
cat3();
}
else if(customKey)
{
if(customKey=='1')
{
myDFPlayer.playFolder(2,1);
delay(100);
Serial.println("TVM_2");
}
else if(customKey=='2')
{
myDFPlayer.playFolder(2,2);
delay(100);
Serial.println("KLM_2");
}
else if(customKey=='3')
{
myDFPlayer.playFolder(2,3);
delay(100);
Serial.println("PTM_2");
customKey=0;
}
else if(customKey=='4')
{
myDFPlayer.playFolder(2,4);
delay(100);
Serial.println("ALP_2");
customKey=0;
}
else if(customKey=='5')
{
myDFPlayer.playFolder(2,5);
delay(100);
Serial.println("KTM_2");
customKey=0;
}
else if(customKey=='6')
{
myDFPlayer.playFolder(2,6);
delay(100);
Serial.println("IDK_2");
customKey=0;
}
else if(customKey=='7')
{
myDFPlayer.playFolder(2,7);
delay(100);
Serial.println("EKM_2");
customKey=0;
}
else if(customKey=='8')
{
myDFPlayer.playFolder(2,8);
delay(100);
Serial.println("THR_2");
customKey=0;
}
else if(customKey=='9')
{
myDFPlayer.playFolder(2,9);
delay(100);
Serial.println("PKD_2");
customKey=0;
}
else if(customKey=='a')
{
myDFPlayer.playFolder(2,10);
delay(100);
Serial.println("MLP_2");
customKey=0;
}
else if(customKey=='b')
{
myDFPlayer.playFolder(2,11);
delay(100);
Serial.println("KZD_2");
customKey=0;
}
else if(customKey=='c')
{
myDFPlayer.playFolder(2,12);
delay(100);
Serial.println("WYD_2");
customKey=0;
}
else if(customKey=='d')
{
myDFPlayer.playFolder(2,13);
delay(100);
Serial.println("KNR_2");
customKey=0;
}
else if(customKey=='e')
{
myDFPlayer.playFolder(2,14);
delay(100);
Serial.println("KKD_2");
customKey=0;
}
}}}
void cat3()
{
myDFPlayer.playFolder(15,3);
delay(100);
Serial.println("CAT_3");
char customKey;
while(true)
{
customKey=customKeypad.getKey();
if(customKey=='M')
{++catCount;
if(catCount==4)
catCount=1;
cat1();
}
else if(customKey)
{
if(customKey=='1')
{
myDFPlayer.playFolder(3,1);
delay(100);
Serial.println("TVM_3");
}
else if(customKey=='2')
{
myDFPlayer.playFolder(3,2);
delay(100);
Serial.println("KLM_3");
}
else if(customKey=='3')
{
myDFPlayer.playFolder(3,3);
delay(100);
Serial.println("PTM_3");
customKey=0;
}
else if(customKey=='4')
{
myDFPlayer.playFolder(3,4);
delay(100);
Serial.println("ALP_3");
customKey=0;
}
else if(customKey=='5')
{
myDFPlayer.playFolder(3,5);
delay(100);
Serial.println("KTM_3");
customKey=0;
}
else if(customKey=='6')
{
myDFPlayer.playFolder(3,6);
delay(100);
Serial.println("IDK_3");
customKey=0;
}
else if(customKey=='7')
{
myDFPlayer.playFolder(3,7);
delay(100);
Serial.println("EKM_3");
customKey=0;
}
else if(customKey=='8')
{
myDFPlayer.playFolder(3,8);
delay(100);
Serial.println("THR_3");
customKey=0;
}
else if(customKey=='9')
{
myDFPlayer.playFolder(3,9);
delay(100);
Serial.println("PKD_3");
customKey=0;
}
else if(customKey=='a')
{
myDFPlayer.playFolder(3,10);
delay(100);
Serial.println("MLP_3");
customKey=0;
}
else if(customKey=='b')
{
myDFPlayer.playFolder(3,11);
delay(100);
Serial.println("KZD_3");
customKey=0;
}
else if(customKey=='c')
{
myDFPlayer.playFolder(3,12);
delay(100);
Serial.println("WYD_3");
customKey=0;
}
else if(customKey=='d')
{
myDFPlayer.playFolder(3,13);
delay(100);
Serial.println("KNR_3");
customKey=0;
}
else if(customKey=='e')
{
myDFPlayer.playFolder(3,14);
delay(100);
Serial.println("KKD_3");
customKey=0;
}
}}}