I have a problem with the program shown below, the problem is that I do not know how to play a specific music by pressing a specific key, for example: if key 2 is pressed, track number 2 is played and etc.
I am desperate! I don't know how to solve, here is the program:
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
#define p1 2
#define p2 3
#define p3 4
#define p4 5
#define p5 6
#define p6 7
void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(115200);
pinMode(p1,INPUT_PULLUP);
pinMode(p2,INPUT_PULLUP);
pinMode(p3,INPUT_PULLUP);
pinMode(p4,INPUT_PULLUP);
pinMode(p5,INPUT_PULLUP);
pinMode(p6,INPUT_PULLUP);
myDFPlayer.volume(20); //Set volume value. From 0 to 30
//myDFPlayer.play(1);
}
void loop()
{
myDFPlayer.read();
int val1;
int val2;
int val3;
int val4;
int val5;
int val6;
val1 =digitalRead(p1);
val2= digitalRead(p2);
val3= digitalRead(p3);
val4= digitalRead(p4);
val5= digitalRead(p5);
val6= digitalRead(p6);
if(val1 == 1){
myDFPlayer.play(1);
}
if(val2 == 1){
myDFPlayer.play(2);
}
if(val3 == 1){
myDFPlayer.play(3);
}
if(val4 == 1){
myDFPlayer.play(4);
}
if(val5 == 1){
myDFPlayer.play(5);
}
if(val6 == 1){
myDFPlayer.play(6);
}
}
thanks to anyone who answers me