Jeux quizz 4 joueurs avec lecture de MP3

bonjour à tous je me suis lancé dans la création d'un jeux de buzzer avec comptage des points qui fonctionne très bien sur une carte Arduino UNO mais je souhaite l'améliorer avec la lecture de sons MP3 différents selon si on donne la bonne réponse ou la mauvaise ou encore si on a gagné ( le 1er à 10 points) et pour en rajouter une couche j'aimerai une lecture aléatoire de son "YES", "NO"or "WIN".
c'est là que ça se complique : je veux utiliser un lecteur MP3 série YX5300 avec une carte SD avec 3 fichiers (YES,NO et WIN) et je bloque complètement sur la programmation de ce module.
Y a t'il quelqu'un qui a déjà travailler dessus et qui pourrait m'aider
merci à tous.

Bonjour

Tout d'abord, bravo pour cette réalisation, superbe!

J'ai utilisé ce type de cartes MP3 série (sans bibliothèque), si ton Arduino n'a que le port Serial, tu dois utiliser la bibliothèque SoftwareSerial (Inclue dans l'IDE Arduino) pour ajouter un port série pour commander cette carte.
Le truc important est la disposition des fichiers sur la carte SD (FAT16 ou FAT32), ainsi, dans ton cas, il faut faire un répertoire qui s'appellera 01 dans lequel il y aura les fichiers 01_YES.MP3, 02_NO.MP3 et 03_WIN.MP3. L'important est le 01_... 02_... 03_...etc.

Je me suis basé sur cet exemple pour développer avec cette carte.

Si tu ne t'en sors pas avec cet exemple, je peux adapter le mien à ton besoin.

Cordialement
jpbbricole

Merci c'est mon premier projet perso en Arduino
j'ai déjà regardé cet exemple
je voulais préciser:
dans le cas d'une bonne réponse, je souhaite diffuser une des musiques du dossier YES aléatoire
de même que pour la mauvaise réponse une des musiques du dossier NO
et dans le cas d'un gagnant une des musiques du dossier WIN.
c'est déjà un gros problème a résoudre je pense...
diffuser la musique c'est facile avec le moniteur mais je bloque sur le lien à faire avec mon programme
bref je me décourage pas mais pour le moment j'ai besoin de conseil
en tout cas merci de ta réponse

Bonjour

Ok, c'est un peu plus claire, donc tu dois organiser tes répertoires ainsi:
3 répertoires, 01, 02, 03
01 contient 001_YES1.mp3, 001_YES2.mp3, 001_YES3.mp3, 001_YES4.mp3.....
02 contient 001_NO1.mp3, 001_NO2.mp3.....
03 contient 001_WIN1.mp3, 001_WIN2.mp3.....

Tu définis une variable qui vaudra 1 pour dans le cas d'un YES, 2 pour NO et 3 pour WIN. Cette variable devient l'index du répertoire.
Tu définis une variable pour le numéro du MP3, variable qui sera "remplie" par la fonction de générateur aléatoire random()
Tu as, ainsi, le répertoire et le fichier en fonction de la situation.

Comme ça fait un moment que je n'ai pas fait ça, j'essaie ce soir et te redis.

Cordialement
jpbbricole

merci pour ton aide
je vais essayer cela pour le moment je fais des gros travaux à la maison de je pourrais pas l'essayer tout de suite
c'est cool
tu me diras si ton test est concluant
cordialement

Bonjour

Ca marche super bien!!
Je te mets ça en ligne, demain dans la journée.

Cordialement
jpbbricole

Bonjour

Voilà, je t'ai fait un petit exemple avec 3 répertoires avec chacuns 4 (repNombreMp3) MP3.
01/001_xxx.MP3, 002_xxx.MP3, 003_xxx.MP3, 004_xxx.MP3
02/001_xxx.MP3, 002_xxx.MP3, 003_xxx.MP3, 004_xxx.MP3
03/001_xxx.MP3, 002_xxx.MP3, 003_xxx.MP3, 004_xxx.MP3

Le câblage de la carte MP3
Rx sur pin 2 Arduino
Tx sur pin 3 Arduino

Il y a 3 boutons pour la démo
btnYESpin pin 8
btnNOpin pin 9
btnWIN pin 10

Ces boutons sont actifs à 0 (INPUT_PULLUP, btnEtatPresse 0 donc câblés au GND)

Dans ton programme pour;
démarrer la lecture d'un fichier MP3, il suffit de faire:
mp3PlayFolderFile(1, 3);
pour jouer le MP3 003_xxx.MP3 dans le répertoire 01

jouer un MP3 au hasard, en fonction des états YES, NO ou WIN:
mp3PlayFolderRndFile(folderXXX); (selon enum foldersIndex)

Pour le générateur pseudo-aléatoire il y a:
randomSeed(analogRead(0)); // Pour l'initialisation
et
random(1, repNombreMp3 +1); // Pour choisir le fichier MP3

/*
    Name:       ARDFR_Eppler314_MP3serial.ino
    Created:	05.05.2021
    Author:     jpbbricole
*/

//------------------------------------- Port série
#include <SoftwareSerial.h>
#define mp3SerialRxPin 3                                            //should connect to TX of the Serial MP3 Player module
#define mp3SerialTxPin 2                                            //connect to RX of the module
SoftwareSerial mp3Serial(mp3SerialRxPin, mp3SerialTxPin);

//------------------------------------- Carte MP3 série
static int8_t mp3SendBuffer[8] = {0} ;
#define mp3CmdSetVolume 0X06
#define mp3CmdSelDevice 0X09
#define mp3CmdSelSdCard 0X02
#define mp3CmdPlayFoldFile 0X0F

//------------------------------------- Boutons
#define btnYESpin 8
#define btnNOpin 9
#define btnWINpin 10
#define btnEtatPresse 0          // Etat lu d'un bouton pressé

enum foldersIndex {folder0, folderYES, folderNO, folderWIN};

#define repNombreMp3 4           // Nombre de fichiers MP3 par repertoire      

void setup()
{
	
	Serial.begin(115200);
	mp3Serial.begin(9600);
	delay(500);							                             //Wait chip initialization is complete
	
	pinMode(btnYESpin, INPUT_PULLUP);
	pinMode(btnNOpin, INPUT_PULLUP);
	pinMode(btnWINpin, INPUT_PULLUP);

	randomSeed(analogRead(0));
	
	mp3IfaceSendCommand(mp3CmdSelDevice, mp3CmdSelSdCard);           //selectionner la carte SD
	delay(200);
	mp3IfaceSendCommand(mp3CmdSetVolume, 0X0012);                    // Régler le volume
	
	//mp3PlayFolderFile(1, 1);
	//delay(4000);
	
}

void loop()
{
	int btnPin = 0;
	
	if (digitalRead(btnYESpin) == btnEtatPresse)
	{
		mp3PlayFolderRndFile(folderYES);
		btnPin = btnYESpin;
	} 
	else if (digitalRead(btnNOpin) == btnEtatPresse)
	{
		mp3PlayFolderRndFile(folderNO);
		btnPin = btnNOpin;
	}
	else if (digitalRead(btnWINpin) == btnEtatPresse)
	{
		mp3PlayFolderRndFile(folderWIN);
		btnPin = btnWINpin;
	}
	if (btnYESpin != 0)      // Si un bouton a été pressé
	{
		while(digitalRead(btnPin) == btnEtatPresse){}	// Attendre le relachement du bouton	
		btnPin = 0;
	}
}

void mp3PlayFolderRndFile(int folderIndex)
{
	int mp3Index = random(1, repNombreMp3 +1);

	Serial.println("Folder " + String(folderIndex) + "\tMP3 " + String(mp3Index));	
	mp3PlayFolderFile(folderIndex, mp3Index);
	delay(500);                                           
}

void mp3PlayFolderFile(int numFolder, int numFile)//, int16_t sndLevel)
{
	int16_t cmdParam = numFile + ( numFolder <<8);
	mp3IfaceSendCommand(mp3CmdPlayFoldFile, cmdParam);

	if (numFolder == 0 && numFile == 0)
	{
		Serial.println("Play sound ABORT");
	} 
	else
	{
		Serial.println("Play sound " + String(numFolder) + "-" + String(numFile));
	}
}
void mp3IfaceSendCommand(int8_t command, int16_t dat)
{
	delay(20);
	mp3SendBuffer[0] = 0x7e;                                         //starting byte
	mp3SendBuffer[1] = 0xff;                                         //version
	mp3SendBuffer[2] = 0x06;                                         //the number of bytes of the command without starting byte and ending byte
	mp3SendBuffer[3] = command;
	mp3SendBuffer[4] = 0x00;                                         //0x00 = no feedback, 0x01 = feedback
	mp3SendBuffer[5] = (int8_t)(dat >> 8);                           //datah
	mp3SendBuffer[6] = (int8_t)(dat);                                //datal
	mp3SendBuffer[7] = 0xef;                                         //ending byte
	for(uint8_t i=0; i<8; i++)
	{
		mp3Serial.write(mp3SendBuffer[i]) ;
	}
}

A+
Cordialement
jpbbricole

bonjour
Super je vais pouvoir l'essayer ce week end
car demain je finis mes travaux de la maison
je suis trop content
j'avais câblé aussi les boutons actif à 0
un grand merci pour ton aide ce sera plus fun avec le son
j'ai hate comme ça il sera terminé
je te tiens informer de mes essais
bonne soirée
cordialement

bonsoir
je pas vraiment eu le temps d'essayer correctement
mais mon premier et seul test était négatif
j'ai pas eu non plus l'esprit concentré et comme le module mp3
m'est complètement inconnu je ne sais pas avancé
je reprends ce projet très vite j'espère
en tout cas merci de ton aide
A+

bonsoir jpbbricole
j'espère que tu vas bien
moi j'ai eu d'autres projets en bois ainsi que des travaux à la maison
il le faut de temps en temps pour satisfaire tout le monde
j'ai essayer un peu ton programme adapté à ma configuration mais ça ne donne rien
je suis nul avec ce lecteur MP3

je te montre mon prog tu me diras ce que tu en penses
moi je sais plus j'ai la tête embrouillée
j'ai besoin de vacance
en tout cas merci de ton aide

//We always have to include the library
#include "LedControl.h"
#include "SoftwareSerial.h"
#define mp3SerialRxPin 0 //should connect to TX of the Serial MP3 Player module
#define mp3SerialTxPin 1 //connect to RX of the module
SoftwareSerial mp3Serial(mp3SerialRxPin, mp3SerialTxPin);

//------------------------------------- Carte MP3 série
static int8_t mp3SendBuffer[8] = {0} ;
#define mp3CmdSetVolume 0X06
#define mp3CmdSelDevice 0X09
#define mp3CmdSelSdCard 0X02
#define mp3CmdPlayFoldFile 0X0F

enum foldersIndex {folderYES, folderNO, folderWIN};

#define repNombreMp3 2 // Nombre de fichiers MP3 par repertoire

const int ButtonPin1 = A0; //J
const int ButtonPin2 = A1; //R Quatres boutons poussoirs pour
const int ButtonPin3 = A2; //B faire les BUZZERS
const int ButtonPin4 = A3; //V
//const int ButtonPinRESET = 11; //
const int ButtonPinY = A4; //YES
const int ButtonPinN = A5; //NO
const int LedPin1 = 2; //J
const int LedPin2 = 3; //R Quatres LED pour faire
const int LedPin3 = 4; //B le voyant du BUZZER le + Rapide
const int LedPin4 = 5; //V
const int LedPinY = 6; //YES
const int LedPinN = 7; //NO

int Buttonstate1 = 1; //
int Buttonstate2 = 1; // Initialisation des variables à 0
int Buttonstate3 = 1; //
int Buttonstate4 = 1; //
int ButtonstateY = 1; //
int ButtonstateN = 1; //
int Counter1 = 0; //
int Counter2 = 0; // compteur du joueur
int Counter3 = 0; //
int Counter4 = 0; //
int CounterW = 10; // nombre de bonnes réponses
int Winner = 0; // un gagnant ?
int NumWinner = 0; // numéro du joueur gagnant
LedControl lc=LedControl(12,13,10,1);

unsigned long delaytime=1000; /* we always wait a bit between updates of the display */

void setup() {
pinMode(LedPin1, OUTPUT); //
pinMode(LedPin2, OUTPUT); // Initialisation des LEDs en Sortie de l'Arduino
pinMode(LedPin3, OUTPUT); //
pinMode(LedPin4, OUTPUT); //
pinMode(LedPinY, OUTPUT); //
pinMode(LedPinN, OUTPUT); //

pinMode(ButtonPin1, INPUT); //
pinMode(ButtonPin2, INPUT); // Initialisation des Boutons en Entrée de l'Arduino
pinMode(ButtonPin3, INPUT); //
pinMode(ButtonPin4, INPUT); //
pinMode(ButtonPinY, INPUT); //
pinMode(ButtonPinN, INPUT); //
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
/
lc.shutdown(0,false);
/
Set the brightness to a medium values /
lc.setIntensity(0,8);
/
and clear the display */
lc.clearDisplay(0);

Serial.begin(115200);
mp3Serial.begin(9600);
delay(500); //Wait chip initialization is complete

randomSeed(analogRead(0));
mp3IfaceSendCommand(mp3CmdSelDevice, mp3CmdSelSdCard); //selectionner la carte SD
delay(200);
mp3IfaceSendCommand(mp3CmdSetVolume, 0X0012); // Régler le volume

}

/*
This method will display the characters for the
word "Arduino" one after the other on digit 0.
*/
void writeArduinoOn7Segment() {
lc.setChar(0,0,Counter1,false);

lc.setChar(0,2,Counter2,false);

lc.setChar(0,4,Counter3,false);

lc.setChar(0,6,Counter4,false);

}

void loop() {
writeArduinoOn7Segment();
//scrollDigits();
// Nous effectuons une lecture des boutons 1 à 4 ainsi que le bouton RESET, nous pouvons ensuite
// travailler sur les valeurs (Haut ou Bas) des boutons...
digitalWrite(LedPin1, LOW);
digitalWrite(LedPin2, LOW);
digitalWrite(LedPin3, LOW);
digitalWrite(LedPin4, LOW);
digitalWrite(LedPinY, LOW);
digitalWrite(LedPinN, LOW);

// --- Etude de Cas ---

// *** Cas du Bouton 1 ***

Buttonstate1 = digitalRead(ButtonPin1);
if (Buttonstate1 == LOW) // Si le bouton 1 est activé
{
digitalWrite(LedPin1, HIGH); // Allumer la led du bouton 1
digitalWrite(LedPinY, HIGH); // LED reponse activé
delay(1000);
digitalWrite(LedPinY, LOW); // LED reponse désactivé
while (1)
{
ButtonstateY = digitalRead(ButtonPinY);
ButtonstateN = digitalRead(ButtonPinN);
if (ButtonstateY == LOW)
{
mp3PlayFolderRndFile(folderYES);
Counter1 ++;
digitalWrite(LedPinY, HIGH);
digitalWrite(LedPin1, HIGH);
delay(1000);
digitalWrite(LedPinY, LOW);
digitalWrite(LedPin1, LOW);
if (Counter1 == CounterW)
{
Winner = 1;
NumWinner = 1;
break;
}
break;
}
if (ButtonstateN == LOW)
{
mp3PlayFolderRndFile(folderNO);
Counter1 = Counter1;
digitalWrite(LedPinN, HIGH);
digitalWrite(LedPin1, HIGH);
delay(1000);
digitalWrite(LedPinN, LOW);
digitalWrite(LedPin1, LOW);
break;
}

  }


Buttonstate1 = 1;
ButtonstateY = 1;
ButtonstateN = 1;

}

// *** Cas du Bouton 2 ***

Buttonstate2 = digitalRead(ButtonPin2);
if (Buttonstate2 == LOW) // Si le bouton 2 est activé
{
digitalWrite(LedPin2, HIGH); // Allumer la led du bouton 2
digitalWrite(LedPinY, HIGH); // LED reponse activé
delay(1000);
digitalWrite(LedPinY, LOW); // LED reponse désactivé
while (1)
{
ButtonstateY = digitalRead(ButtonPinY);
ButtonstateN = digitalRead(ButtonPinN);
if (ButtonstateY == LOW)
{
mp3PlayFolderRndFile(folderYES);
Counter2 ++;
digitalWrite(LedPinY, HIGH);
digitalWrite(LedPin2, HIGH);
delay(1000);
digitalWrite(LedPinY, LOW);
digitalWrite(LedPin2, LOW);
if (Counter2 == CounterW)
{
Winner = 1;
NumWinner = 2;
break;
}
break;
}
if (ButtonstateN == LOW)
{
mp3PlayFolderRndFile(folderNO);
Counter2 = Counter2;
digitalWrite(LedPinN, HIGH);
digitalWrite(LedPin2, HIGH);
delay(1000);
digitalWrite(LedPinN, LOW);
digitalWrite(LedPin2, LOW);
break;
}

  }


Buttonstate2 = 1;
ButtonstateY = 1;
ButtonstateN = 1;

}

// *** Cas du Bouton 3 ***

Buttonstate3 = digitalRead(ButtonPin3);
if (Buttonstate3 == LOW) // Si le bouton 3 est activé
{
digitalWrite(LedPin3, HIGH); // Allumer la led du bouton 3
digitalWrite(LedPinY, HIGH); // LED reponse activé
delay(1000);
digitalWrite(LedPinY, LOW); // LED reponse désactivé
while (1)
{
ButtonstateY = digitalRead(ButtonPinY);
ButtonstateN = digitalRead(ButtonPinN);
if (ButtonstateY == LOW)
{
mp3PlayFolderRndFile(folderYES);
Counter3 ++;
digitalWrite(LedPinY, HIGH);
digitalWrite(LedPin3, HIGH);
delay(1000);
digitalWrite(LedPinY, LOW);
digitalWrite(LedPin3, LOW);
if (Counter3 == CounterW)
{
Winner = 1;
NumWinner = 3;
break;
}
break;
}
if (ButtonstateN == LOW)
{
mp3PlayFolderRndFile(folderNO);
Counter3 = Counter3;
digitalWrite(LedPinN, HIGH);
digitalWrite(LedPin3, HIGH);
delay(1000);
digitalWrite(LedPinN, LOW);
digitalWrite(LedPin3, LOW);
break;
}

  }


Buttonstate3 = 1;
ButtonstateY = 1;
ButtonstateN = 1;

}

// *** Cas du Bouton 4 ***

Buttonstate4 = digitalRead(ButtonPin4);
if (Buttonstate4 == LOW) // Si le bouton 4 est activé
{
digitalWrite(LedPin4, HIGH); // Allumer la led du bouton 4
digitalWrite(LedPinY, HIGH); // LED reponse activé
delay(1000);
digitalWrite(LedPinY, LOW); // LED reponse désactivé
while (1)
{
ButtonstateY = digitalRead(ButtonPinY);
ButtonstateN = digitalRead(ButtonPinN);
if (ButtonstateY == LOW)
{
mp3PlayFolderRndFile(folderYES);
Counter4 ++;
digitalWrite(LedPinY, HIGH);
digitalWrite(LedPin4, HIGH);
delay(1000);
digitalWrite(LedPinY, LOW);
digitalWrite(LedPin4, LOW);
if (Counter4 == CounterW)
{
Winner = 1;
NumWinner = 4;
break;
}
break;
}
if (ButtonstateN == LOW)
{
mp3PlayFolderRndFile(folderNO);
Counter4 = Counter4;
digitalWrite(LedPinN, HIGH);
digitalWrite(LedPin4, HIGH);
delay(1000);
digitalWrite(LedPinN, LOW);
digitalWrite(LedPin4, LOW);
break;
}

  }


Buttonstate4 = 1;
ButtonstateY = 1;
ButtonstateN = 1;

}

if (Winner == 1)
{
mp3PlayFolderRndFile(folderWIN);
switch (NumWinner)
{
case 1:
digitalWrite(LedPin1, HIGH);
break;
case 2:
digitalWrite(LedPin2, HIGH);
break;
case 3:
digitalWrite(LedPin3, HIGH);
break;
case 4:
digitalWrite(LedPin4, HIGH);
break;
}
digitalWrite(LedPinY, HIGH);
delay(1000);
digitalWrite(LedPinN, HIGH);
digitalWrite(LedPinY, LOW);
delay(1000);
digitalWrite(LedPinN, LOW);
digitalWrite(LedPinY, HIGH);
delay(1000);
digitalWrite(LedPinN, HIGH);
digitalWrite(LedPinY, LOW);
delay(1000);
Winner = 0;
Counter1 = 0;
Counter2 = 0;
Counter3 = 0;
Counter4 = 0;
NumWinner = 0;
digitalWrite(LedPin1, LOW);
digitalWrite(LedPin2, LOW);
digitalWrite(LedPin3, LOW);
digitalWrite(LedPin4, LOW);
Buttonstate1 = 0;
Buttonstate2 = 0;
Buttonstate3 = 0;
Buttonstate4 = 0;
ButtonstateY = 0;
ButtonstateN = 0;
}
}
void mp3PlayFolderRndFile(int folderIndex)
{
int mp3Index = random(1, repNombreMp3 +1);

Serial.println("Folder " + String(folderIndex) + "\tMP3 " + String(mp3Index));
mp3PlayFolderFile(folderIndex, mp3Index);
delay(500);
}

void mp3PlayFolderFile(int numFolder, int numFile)//, int16_t sndLevel)
{
int16_t cmdParam = numFile + ( numFolder <<8);
mp3IfaceSendCommand(mp3CmdPlayFoldFile, cmdParam);

if (numFolder == 0 && numFile == 0)
{
Serial.println("Play sound ABORT");
}
else
{
Serial.println("Play sound " + String(numFolder) + "-" + String(numFile));
}
}
void mp3IfaceSendCommand(int8_t command, int16_t dat)
{
delay(20);
mp3SendBuffer[0] = 0x7e; //starting byte
mp3SendBuffer[1] = 0xff; //version
mp3SendBuffer[2] = 0x06; //the number of bytes of the command without starting byte and ending byte
mp3SendBuffer[3] = command;
mp3SendBuffer[4] = 0x00; //0x00 = no feedback, 0x01 = feedback
mp3SendBuffer[5] = (int8_t)(dat >> 8); //datah
mp3SendBuffer[6] = (int8_t)(dat); //datal
mp3SendBuffer[7] = 0xef; //ending byte
for(uint8_t i=0; i<8; i++)
{
mp3Serial.write(mp3SendBuffer[i]) ;
}
}

:warning: La rédaction de votre message ne répond pas aux critères attendus. Merci de prendre en compte et mettre en application les recommandations listées dans « Les bonnes pratiques du Forum Francophone”

[quote="eppler314, post:10, topic:857147"]
bonsoir jpbbricole
j'espère que tu vas bien
moi j'ai eu d'autres projets en bois ainsi que des travaux à la maison
il le faut de temps en temps pour satisfaire tout le monde
j'ai essayer un peu ton programme adapté à ma configuration mais ça ne donne rien
je suis nul avec ce lecteur MP3

je te montre mon prog tu me diras ce que tu en penses
moi je sais plus j'ai la tête embrouillée
j'ai besoin de vacance
en tout cas merci de ton aide

//We always have to include the library
#include "LedControl.h"
#include "SoftwareSerial.h"
#define mp3SerialRxPin 0                                            //should connect to TX of the Serial MP3 Player module
#define mp3SerialTxPin 1                                            //connect to RX of the module
SoftwareSerial mp3Serial(mp3SerialRxPin, mp3SerialTxPin);

//------------------------------------- Carte MP3 série
static int8_t mp3SendBuffer[8] = {0} ;
#define mp3CmdSetVolume 0X06
#define mp3CmdSelDevice 0X09
#define mp3CmdSelSdCard 0X02
#define mp3CmdPlayFoldFile 0X0F

enum foldersIndex {folderYES, folderNO, folderWIN};

#define repNombreMp3 2           // Nombre de fichiers MP3 par repertoire      


const int ButtonPin1 = A0;             //J
const int ButtonPin2 = A1;            //R Quatres boutons poussoirs pour
const int ButtonPin3 = A2;           //B faire les BUZZERS
const int ButtonPin4 = A3;          //V
//const int ButtonPinRESET = 11;   //
const int ButtonPinY = A4;        //YES
const int ButtonPinN = A5;       //NO
const int LedPin1 = 2;          //J
const int LedPin2 = 3;         //R  Quatres LED pour faire
const int LedPin3 = 4;        //B  le voyant du BUZZER le + Rapide
const int LedPin4 = 5;       //V
const int LedPinY = 6;      //YES
const int LedPinN = 7;     //NO

int Buttonstate1 = 1;          //
int Buttonstate2 = 1;         //  Initialisation des variables à 0
int Buttonstate3 = 1;        //
int Buttonstate4 = 1;       //
int ButtonstateY = 1;      //
int ButtonstateN = 1;     //
int Counter1 = 0;           // 
int Counter2 = 0;          // compteur du joueur 
int Counter3 = 0;         // 
int Counter4 = 0;        //
int CounterW = 10;      // nombre de bonnes réponses
int Winner = 0;        // un gagnant ?
int NumWinner = 0;    // numéro du joueur gagnant
LedControl lc=LedControl(12,13,10,1);


unsigned long delaytime=1000;  /* we always wait a bit between updates of the display */

void setup() {
  pinMode(LedPin1, OUTPUT); //
  pinMode(LedPin2, OUTPUT); //  Initialisation des LEDs en Sortie de l'Arduino
  pinMode(LedPin3, OUTPUT); //
  pinMode(LedPin4, OUTPUT); //
  pinMode(LedPinY, OUTPUT); //
  pinMode(LedPinN, OUTPUT); //
  
  pinMode(ButtonPin1, INPUT); //
  pinMode(ButtonPin2, INPUT); //  Initialisation des Boutons en Entrée de l'Arduino
  pinMode(ButtonPin3, INPUT); //
  pinMode(ButtonPin4, INPUT); //
  pinMode(ButtonPinY, INPUT); //
  pinMode(ButtonPinN, INPUT); //
  /*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,8);
  /* and clear the display */
  lc.clearDisplay(0);
  
  Serial.begin(115200);
  mp3Serial.begin(9600);
  delay(500);                                          //Wait chip initialization is complete

  randomSeed(analogRead(0));
 mp3IfaceSendCommand(mp3CmdSelDevice, mp3CmdSelSdCard);           //selectionner la carte SD
 delay(200);
  mp3IfaceSendCommand(mp3CmdSetVolume, 0X0012);                    // Régler le volume
   


}


/*
 This method will display the characters for the
 word "Arduino" one after the other on digit 0. 
 */
void writeArduinoOn7Segment() {
  lc.setChar(0,0,Counter1,false);
  
  lc.setChar(0,2,Counter2,false);
  
  lc.setChar(0,4,Counter3,false);
  
  lc.setChar(0,6,Counter4,false);

} 


void loop() { 
  writeArduinoOn7Segment();
  //scrollDigits();
  // Nous effectuons une lecture des boutons 1 à 4 ainsi que le bouton RESET, nous pouvons ensuite 
  // travailler sur les valeurs (Haut ou Bas) des boutons...
  digitalWrite(LedPin1, LOW);
  digitalWrite(LedPin2, LOW);
  digitalWrite(LedPin3, LOW);
  digitalWrite(LedPin4, LOW);
  digitalWrite(LedPinY, LOW);
  digitalWrite(LedPinN, LOW);
  
   //  ***---*** Etude de Cas ***---***
   
//  *** Cas du Bouton 1 ***

  Buttonstate1 = digitalRead(ButtonPin1);
  if (Buttonstate1 == LOW) // Si le bouton 1 est activé
  {
    digitalWrite(LedPin1, HIGH); // Allumer la led du bouton 1
    digitalWrite(LedPinY, HIGH); // LED reponse activé
    delay(1000);
    digitalWrite(LedPinY, LOW);  // LED reponse désactivé
    while (1)
    {
        ButtonstateY = digitalRead(ButtonPinY);
        ButtonstateN = digitalRead(ButtonPinN);
        if (ButtonstateY == LOW)
          {
          mp3PlayFolderRndFile(folderYES);
          Counter1 ++;
        digitalWrite(LedPinY, HIGH);
        digitalWrite(LedPin1, HIGH);
        delay(1000);
        digitalWrite(LedPinY, LOW);
        digitalWrite(LedPin1, LOW);
        if (Counter1 == CounterW) 
          {
          Winner = 1;
            NumWinner = 1;
              break;
          }
            break;
          }
        if (ButtonstateN == LOW)
          {
          mp3PlayFolderRndFile(folderNO);  
          Counter1 = Counter1;
        digitalWrite(LedPinN, HIGH);
        digitalWrite(LedPin1, HIGH);
        delay(1000);
        digitalWrite(LedPinN, LOW);
        digitalWrite(LedPin1, LOW);
        break;
          }
       

      }
    
   
    Buttonstate1 = 1;
    ButtonstateY = 1;
    ButtonstateN = 1;
  } 
   
  //  *** Cas du Bouton 2 ***

  Buttonstate2 = digitalRead(ButtonPin2);
  if (Buttonstate2 == LOW) // Si le bouton 2 est activé
  {
    digitalWrite(LedPin2, HIGH); // Allumer la led du bouton 2
    digitalWrite(LedPinY, HIGH); // LED reponse activé
    delay(1000);
    digitalWrite(LedPinY, LOW);  // LED reponse désactivé
    while (1)
    {
        ButtonstateY = digitalRead(ButtonPinY);
        ButtonstateN = digitalRead(ButtonPinN);
        if (ButtonstateY == LOW)
          {
          mp3PlayFolderRndFile(folderYES);
          Counter2 ++;
        digitalWrite(LedPinY, HIGH);
        digitalWrite(LedPin2, HIGH);
        delay(1000);
        digitalWrite(LedPinY, LOW);
        digitalWrite(LedPin2, LOW);
        if (Counter2 == CounterW) 
          {
          Winner = 1;
            NumWinner = 2;
              break;
          }
            break;
          }
        if (ButtonstateN == LOW)
          {
          mp3PlayFolderRndFile(folderNO);
          Counter2 = Counter2;
        digitalWrite(LedPinN, HIGH);
        digitalWrite(LedPin2, HIGH);
        delay(1000);
        digitalWrite(LedPinN, LOW);
        digitalWrite(LedPin2, LOW);
        break;
          }
       

      }
    
   
    Buttonstate2 = 1;
    ButtonstateY = 1;
    ButtonstateN = 1;
  } 
 
 //  *** Cas du Bouton 3 ***

  Buttonstate3 = digitalRead(ButtonPin3);
  if (Buttonstate3 == LOW) // Si le bouton 3 est activé
  {
    digitalWrite(LedPin3, HIGH); // Allumer la led du bouton 3
    digitalWrite(LedPinY, HIGH); // LED reponse activé
    delay(1000);
    digitalWrite(LedPinY, LOW);  // LED reponse désactivé
    while (1)
    {
        ButtonstateY = digitalRead(ButtonPinY);
        ButtonstateN = digitalRead(ButtonPinN);
        if (ButtonstateY == LOW)
          {
          mp3PlayFolderRndFile(folderYES);
          Counter3 ++;
        digitalWrite(LedPinY, HIGH);
        digitalWrite(LedPin3, HIGH);
        delay(1000);
        digitalWrite(LedPinY, LOW);
        digitalWrite(LedPin3, LOW);
        if (Counter3 == CounterW) 
          {
          Winner = 1;
            NumWinner = 3;
              break;
          }
            break;
          }
        if (ButtonstateN == LOW)
          {
          mp3PlayFolderRndFile(folderNO);
          Counter3 = Counter3;
        digitalWrite(LedPinN, HIGH);
        digitalWrite(LedPin3, HIGH);
        delay(1000);
        digitalWrite(LedPinN, LOW);
        digitalWrite(LedPin3, LOW);
        break;
          }
       

      }
    
   
    Buttonstate3 = 1;
    ButtonstateY = 1;
    ButtonstateN = 1;
  } 
  
   //  *** Cas du Bouton 4 ***

  Buttonstate4 = digitalRead(ButtonPin4);
  if (Buttonstate4 == LOW) // Si le bouton 4 est activé
  {
    digitalWrite(LedPin4, HIGH); // Allumer la led du bouton 4
    digitalWrite(LedPinY, HIGH); // LED reponse activé
    delay(1000);
    digitalWrite(LedPinY, LOW);  // LED reponse désactivé
    while (1)
    {
        ButtonstateY = digitalRead(ButtonPinY);
        ButtonstateN = digitalRead(ButtonPinN);
        if (ButtonstateY == LOW)
          {
          mp3PlayFolderRndFile(folderYES);
          Counter4 ++;
        digitalWrite(LedPinY, HIGH);
        digitalWrite(LedPin4, HIGH);
        delay(1000);
        digitalWrite(LedPinY, LOW);
        digitalWrite(LedPin4, LOW);
        if (Counter4 == CounterW) 
          {
          Winner = 1;
            NumWinner = 4;
              break;
          }
            break;
          }
        if (ButtonstateN == LOW)
          {
          mp3PlayFolderRndFile(folderNO);
          Counter4 = Counter4;
        digitalWrite(LedPinN, HIGH);
        digitalWrite(LedPin4, HIGH);
        delay(1000);
        digitalWrite(LedPinN, LOW);
        digitalWrite(LedPin4, LOW);
        break;
          }
       

      }
    
   
    Buttonstate4 = 1;
    ButtonstateY = 1;
    ButtonstateN = 1;
  } 
  
  if (Winner == 1)
    {
    mp3PlayFolderRndFile(folderWIN);
    switch (NumWinner)
      {
      case 1:
      digitalWrite(LedPin1, HIGH);
      break;
      case 2:
      digitalWrite(LedPin2, HIGH);
      break;
      case 3:
      digitalWrite(LedPin3, HIGH);
      break;
      case 4:
      digitalWrite(LedPin4, HIGH);
      break;
      }
    digitalWrite(LedPinY, HIGH);
    delay(1000);
    digitalWrite(LedPinN, HIGH);
    digitalWrite(LedPinY, LOW);
    delay(1000);
    digitalWrite(LedPinN, LOW);
    digitalWrite(LedPinY, HIGH);
    delay(1000);
    digitalWrite(LedPinN, HIGH);
    digitalWrite(LedPinY, LOW);
    delay(1000);
    Winner = 0;
    Counter1 = 0;
    Counter2 = 0;
    Counter3 = 0;
    Counter4 = 0;
    NumWinner = 0;
    digitalWrite(LedPin1, LOW);
    digitalWrite(LedPin2, LOW);
    digitalWrite(LedPin3, LOW);
    digitalWrite(LedPin4, LOW);
    Buttonstate1 = 0;
    Buttonstate2 = 0;
    Buttonstate3 = 0;
    Buttonstate4 = 0;
    ButtonstateY = 0;
    ButtonstateN = 0;
   }
}
void mp3PlayFolderRndFile(int folderIndex)
{
  int mp3Index = random(1, repNombreMp3 +1);

  Serial.println("Folder " + String(folderIndex) + "\tMP3 " + String(mp3Index));  
  mp3PlayFolderFile(folderIndex, mp3Index);
  delay(500);                                           
}

void mp3PlayFolderFile(int numFolder, int numFile)//, int16_t sndLevel)
{
  int16_t cmdParam = numFile + ( numFolder <<8);
  mp3IfaceSendCommand(mp3CmdPlayFoldFile, cmdParam);

  if (numFolder == 0 && numFile == 0)
  {
    Serial.println("Play sound ABORT");
  } 
  else
  {
    Serial.println("Play sound " + String(numFolder) + "-" + String(numFile));
  }
}
void mp3IfaceSendCommand(int8_t command, int16_t dat)
{
  delay(20);
  mp3SendBuffer[0] = 0x7e;                                         //starting byte
  mp3SendBuffer[1] = 0xff;                                         //version
  mp3SendBuffer[2] = 0x06;                                         //the number of bytes of the command without starting byte and ending byte
  mp3SendBuffer[3] = command;
  mp3SendBuffer[4] = 0x00;                                         //0x00 = no feedback, 0x01 = feedback
  mp3SendBuffer[5] = (int8_t)(dat >> 8);                           //datah
  mp3SendBuffer[6] = (int8_t)(dat);                                //datal
  mp3SendBuffer[7] = 0xef;                                         //ending byte
  for(uint8_t i=0; i<8; i++)
  {
    mp3Serial.write(mp3SendBuffer[i]) ;
  }
}

Bonjour eppler314

Oui, super bien, j'espère qu'il en va de même pour toi?
Je suis plus relax depuis que je suis vacciné :blush:

Tout ton programme fonctionne, sauf la partie MP3?

A+
Cordialement
jpbbricole

On devrait décerner un prix spécial pour la plus grosse tartine de code postée sans balises.

Bonjour hbachetti

Il faudrait aussi relever que eppler314 a "corrigé le tir" et que c'est plus à mettre sur l'erreur de manipulation. Il faut dire que ce nouveau forum, au niveau de l'ergonomie ...

Indulgence, indulgence...

Cordialement
jpbbricole

moi aussi vacciné j'attends la seconde dose dans 1 semaine
effectivement tout fonctionne à part la lecture MP3
merci
A+
cordialement

désolé j'ai été trop vite et je suis navré
en tout cas merci pour le prix spécial ...c'était pas voulu

Bonsoir eppler314

Je vais "ausculter" ton programme.

Cordialement
jpbbricole

Bonjour eppler314

Comme on dit, j'ai trouvé le fin mot de l'histoire.

Le problème vient de ça:

#define mp3SerialRxPin 0                                            //should connect to TX of the Serial MP3 Player module
#define mp3SerialTxPin 1                                            //connect to RX of the module
SoftwareSerial mp3Serial(mp3SerialRxPin, mp3SerialTxPin);

Tu mets le port mp3Serial "par dessus" le port de la console!
J'ai corrigé comme ceci:

#define mp3SerialRxPin 9                                            //should connect to TX of the Serial MP3 Player module
#define mp3SerialTxPin 8                                            //connect to RX of the module
SoftwareSerial mp3Serial(mp3SerialRxPin, mp3SerialTxPin);

et les connexions sur la carte MP3,
Arduino D9 sur TX
Arduino D8 sur RX

Un petit contrôle, quand un morceau se joue, donc bien commandé, la LED du module clignote.

Un rectificatif pour ce qui concerne l'arborescence des répertoires et des fichiers, dans le post #7
j'ai indiqué ceci
01/001_xxx.MP3, 002_xxx.MP3, 003_xxx.MP3, 004_xxx.MP3
02/001_xxx.MP3, 002_xxx.MP3, 003_xxx.MP3, 004_xxx.MP3
03/001_xxx.MP3, 002_xxx.MP3, 003_xxx.MP3, 004_xxx.MP3
il faut corriger ainsi:
00/001_xxx.MP3, 002_xxx.MP3, 003_xxx.MP3, 004_xxx.MP3
01/001_xxx.MP3, 002_xxx.MP3, 003_xxx.MP3, 004_xxx.MP3
02/001_xxx.MP3, 002_xxx.MP3, 003_xxx.MP3, 004_xxx.MP3
C'est le nom des répertoires qui changent.

La seule correction de programme est:

#define mp3SerialRxPin 9                                            //should connect to TX of the Serial MP3 Player module
#define mp3SerialTxPin 8                                            //connect to RX of the module

corriger le câblage et les répertoires comme indiqué ci-dessus.

Si tu n'as toujours pas de sons, zip le contenu de ta carte SD et mets le en ligne sur le forum que je puisse investiguer.

Cordialement et chaudement!
jpbbricole

tu es un génie .......
mille merci
je suis trop content
encore merci de ton aide