DFPlayer mini random play function - part two

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:

  1. autostart function
  2. 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.

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.