Correct code and place player menu

Hey,

i hope some can help me, im stuck, programming is not the best kind of thing from me, sorry but i try understand it and learn everytime a little bit more.

I have building a menu for playing different sounds with the same buttons

With this menu you can selected 3 diferent sound folders on the dfplayer module with sd card, when folder 1 is selected in the menu, you can play files with other buttons (on pin 6 and 7), this buttons has other sounds files when you selected a other folder in menu.

When folder 1 is selected, and button pin 6 is pressed, he must playning sound 1,1 thats folder named 1 en file nr 1. (myDFPlayer.playFolder(1,1);
When button 7 is pressed, he must playning sound 1,2, thats de second file in folder 1. (myDFPlayer.playFolder(1,2);

When folder 2 is selected, and button pin 6 is pressed, he must playning sound 2,1 thats folder named 2 en file nr 1. (myDFPlayer.playFolder(2,1);
When button 7 is pressed, he must playning sound 2,2, thats de second file in folder 2. (myDFPlayer.playFolder(2,2);

When folder 3 is selected, and button pin 6 is pressed, he must playning sound 3,1 thats folder named 3 en file nr 1. (myDFPlayer.playFolder(3,1);
When button 7 is pressed, he must playning sound 3,2, thats de second file in folder 2. (myDFPlayer.playFolder(3,2);

The DfPlayer is working fine, i test it without this menu and playing the mp3 file correcty.
But togheter it goes wrong, i think de df player goes in loop from the menu.

Question is, what and where put I the right code to activate button pin 6 and 7 so that the can play the correct files. Hope so anyone can help me, tanks alot

#include <LiquidCrystal_I2C.h> // libreria di gestione del display lcd
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

#define butUp     12     //pulsante SU al pin 12
#define butDown   11     //Pulsante GIU al pin 11
#define butP    10       //Pulsante SELEZIONA al pin 10
#define butM       9     //non utilizzato in questo esempio


//Function
void changeMenu();
void dispMenu();
void mp3Folder1();
void mp3Folder2();
void mp3Folder3();

//Vars
char menu = 0x01;
char set1 = 0x00, set2 = 0x00 , set3 = 0x00;
boolean t_butUp, t_butDown, t_butP, t_butM;

int buttonPin6 = 6;        // button pin for playing mp3 file
int buttonState6 = 0;
int lastButtonState6 = 0;     // previous state of the button
int buttonPushCounter6 = 0;   // counter for the number of button presses
int buttonPin7 = 7;        // button pin for playing mp3 file
int buttonState7 = 0;
int lastButtonState7 = 0;     // previous state of the button
int buttonPushCounter7 = 0;   // counter for the number of button presses

//SoftwareSerial mySoftwareSerial(2, 3); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

//Display Adres
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // definisce la tipologia del display

void setup() {
  lcd.begin(20, 4);
  pinMode(buttonPin6, INPUT); // set button pin to be an input
  pinMode(buttonPin7, INPUT); // set button pin to be an input

  t_butUp   = 0x00;
  t_butDown = 0x00;
  t_butP  = 0x00;
  t_butM  = 0x00;

  //myDFPlayer.playFolder(2, 2);

}

void loop() {

  changeMenu();
  dispMenu();
}


//Funzioni

void changeMenu() {

  if (digitalRead(butUp) == 0x00) {
    t_butUp = 0x01;
  }
  if (digitalRead(butDown) == 0x00) {
    t_butDown = 0x01;
  }
  if (digitalRead(butUp) && t_butUp) {
    t_butUp = 0x00;
    lcd.clear();
    menu++;
    if (menu > 0x03) {
      menu = 0x01;
    }
  }
  if (digitalRead(butDown) && t_butDown) {
    t_butDown = 0x00;
    lcd.clear();
    menu--;
    if (menu < 0x01) {
      menu = 0x03;
    }
  }

}

void dispMenu() {

  switch (menu) {
    case 0x01:
      mp3Folder1();
      break;
    case 0x02:
      mp3Folder2();
      break;
    case 0x03:
      mp3Folder3();
      break;
  }
}

/*Begin of Sound folder 1*/
void mp3Folder1() {
  lcd.setCursor(0, 0);
  lcd.print("Select folder");
  lcd.setCursor(0, 1);
  lcd.print("Sound folder 1");
  if (digitalRead(butP) == 0x00) {
    t_butP = 0x01;
  }
}

/*Begin of Sound folder 2*/
void mp3Folder2() {
  lcd.setCursor(0, 0);
  lcd.print("Select folder");
  lcd.setCursor(0, 1);
  lcd.print("Sound folder 2");
  if (digitalRead(butP) == 0x00) {
    t_butP = 0x01;
  }
}


/*Begin of Sound folder 3*/
void mp3Folder3() {
  lcd.setCursor(0, 0);
  lcd.print("Select folder");
  lcd.setCursor(0, 1);
  lcd.print("Sound folder 3");
  if (digitalRead(butP) == 0x00) {
    t_butP = 0x01;
  }
}

int buttonPin6 = 6;        // button pin for playing mp3 file
int buttonPin7 = 7;        // button pin for playing mp3 file

Why do you have two switches for playing the mp3 file?

If the idea is that pin 6 is used to play track 1, and pin 7 is used to play track 2, then the number in the variable name should reflect the track number, not the pin number.

void loop() {

  changeMenu();
  dispMenu();
}

The ONLY excuse for putting the { on the same line as the function/statement is to save real estate. You look pretty stupid then putting in a blank line as the next line. Put the { on a line BY ITSELF.

All the action should happen in loop() or a function called by loop(). Which of those functions seems appropriate for reading the state of a switch or playing an mp3 file? Neither of mine, to my pea brain.

So, it is really hard to understand what you are trying to do, or what problem you are having.

The reason why are 2 buttons is correct, 1 button when pressed play file 1 and other button when pressed is play file 2, but when i in other menu, sound folder 2, than he must the other files in folder 2.

Its just like a soundbox.

On the SD cart are many maps/folders 1, 2, 3, 4, 5 ect and in further way, maybe 1 selected more buttons, but thats for later, first tryin to understand this thing.

{ wil correct that, yes stupid :confused: