Referring to my old post (DFPlayer mini random play function - #6):
one year ago I asked the community for helping me to program a DFPlayer mini module with Arduino uno rev3 so that it had the following functions:
- autostart function
- random play
3 stop at the end of the playlist.
So thanks to the help of the user "markd833" I succeeded in my aim.
Now I ask you helping me again:
to the code suggested by markd833 I would like to add commands to increase or decrease the volume using two analog buttons.
In internet I found the page of this user showing a connection scheme and its related code (Mp3 Player Using DF Player - Full Design Details | Homemade Circuit Projects)
Program for push button control:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00
const int btnNext = A0;
const int btnPause = A1;
const int btnPrevious = A2;
const int volumeUP = A3;
const int volumeDOWN = A4;
int volume = 15;
boolean Playing = false;
void setup ()
{
pinMode(btnPause, INPUT);
pinMode(btnNext, INPUT);
pinMode(btnPrevious, INPUT);
pinMode(volumeUP, INPUT);
pinMode(volumeDOWN, INPUT);
digitalWrite(btnPause, HIGH);
digitalWrite(btnNext, HIGH);
digitalWrite(btnPrevious, HIGH);
digitalWrite(volumeUP, HIGH);
digitalWrite(volumeDOWN, HIGH);
mySerial.begin(9600);
delay(1000);
playFirst();
Playing = true;
}
void loop ()
{
if (digitalRead(btnPause) == LOW)
{
if(Playing)
{
pause();
Playing = false;
}
else
{
Playing = true;
play();
}
}
if (digitalRead(btnNext) == LOW)
{
if(Playing)
{
next();
}
}
if (digitalRead(btnPrevious) == LOW)
{
if(Playing)
{
previous();
}
}
if(digitalRead(volumeUP) == LOW)
{
volumeINC();
}
if(digitalRead(volumeDOWN) == LOW)
{
volumeDEC();
}
}
void playFirst()
{
exe_cmd(0x3F, 0, 0);
delay(500);
exe_cmd(0x06, 0, volume);
delay(500);
exe_cmd(0x11,0,1);
delay(500);
}
void pause()
{
exe_cmd(0x0E,0,0);
delay(500);
}
void play()
{
exe_cmd(0x0D,0,1);
delay(500);
}
void next()
{
exe_cmd(0x01,0,1);
delay(500);
}
void previous()
{
exe_cmd(0x02,0,1);
delay(500);
}
void volumeINC()
{
volume = volume+1;
if(volume==31)
{
volume=30;
}
exe_cmd(0x06, 0, volume);
delay(500);
}
void volumeDEC()
{
volume = volume-1;
if(volume==-1)
{
volume=0;
}
exe_cmd(0x06, 0, volume);
delay(500);
}
void exe_cmd(byte CMD, byte Par1, byte Par2)
{
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge, Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
for (byte x=0; x<10; x++)
{
mySerial.write(Command_line[x]);
}
}
but i don't know how to integrate it into my program.
Can anyone show me how to integrate button function? (if there ia a simplest solution, you're welcome!)
thanks in advance to anyone, however.