I've made a soundbox with a dfplayer and works fine, just the skecth is big, maybe someone can help me make it smaller and more transparent?
What we see here are buttons available when sample bank 1 is selected, 8 sounds are available from folder 01, this repeats itself as sample bank 2, it retrieves the sounds from folder 02. This is repeated 10 times so the sketch gets huge big.
Maybe someone has a solution to this? to make it easier to make it clear? Thank you
Here the code, when select mp3 bank1
void mp3Bank1(){
lcd.print("MP3 bank 1");
val = analogRead(btns);
if (val >= 400 && val <= 445)
{
myDFPlayer.playFolder(01, 1);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 1");
}
else if (val >= 445 && val <= 480)
{
myDFPlayer.playFolder(01, 2);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 2");
}
else if (val >= 480 && val <= 520)
{
myDFPlayer.playFolder(01, 3);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 3");
}
else if (val >= 520 && val <= 570)
{
myDFPlayer.playFolder(01, 4);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 4");
}
else if (val >= 570 && val <= 630)
{
myDFPlayer.playFolder(01, 5);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 5");
}
else if (val >= 630 && val <= 700)
{
myDFPlayer.playFolder(01, 6);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 6");
}
else if (val >= 700 && val <= 800)
{
myDFPlayer.playFolder(01, 7);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 7");
}
else if (val >= 800 && val <= 900)
{
myDFPlayer.playFolder(01, 8);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 8");
}
So this is working fine, when select mp3 bank 2, its the same code, only folder and display print changed:
void mp3Bank2(){
lcd.print("MP3 bank 2");
val = analogRead(btns);
if (val >= 400 && val <= 445)
{
myDFPlayer.playFolder(02, 1);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 1");
}
else if (val >= 445 && val <= 480)
{
myDFPlayer.playFolder(02, 2);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 2");
}
else if (val >= 480 && val <= 520)
{
myDFPlayer.playFolder(02, 3);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 3");
}
else if (val >= 520 && val <= 570)
{
myDFPlayer.playFolder(02, 4);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 4");
}
else if (val >= 570 && val <= 630)
{
myDFPlayer.playFolder(02, 5);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 5");
}
else if (val >= 630 && val <= 700)
{
myDFPlayer.playFolder(02, 6);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 6");
}
else if (val >= 700 && val <= 800)
{
myDFPlayer.playFolder(02, 7);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 7");
}
else if (val >= 800 && val <= 900)
{
myDFPlayer.playFolder(02, 8);
lcd.setCursor(0, 4);
lcd.print("Playing: Sound 8");
}
So and there is a mp3 bank 3, and mp3 bank 4 and 5 and 6 and 7 till 10
So the code is very long, can some help me to make it easier?
Thanks