DFPlayer mini / MP3-TF-16p coding issue

Hi everyone

I’m using for the first time this DFPlayer.

I have already a code but I integrated on some lines for the audio.

To shorten things, below you will find my wokwi project (You will not find the lines for the Dfplayer programming)

Below also my real uploaded code to the Arduino board (Almost same wokwi code + audio coding)

The idea of the project is to choose a category of questions (Blue Buttons) and then pick the right answer (Green buttons)

For each choice an audio is played

Here what happen (Link to the video below):

the audio will work only when i choose the first answer (One of these green buttons/leds)

and then all buttons / leds will not work anymore (for making other choices)..

Could you please help .THANKS

#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include <LedControl.h>
static const uint8_t PIN_MP3_TX = 18; 
static const uint8_t PIN_MP3_RX = 19;

SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
DFRobotDFPlayerMini MP3player;

const int buzzer = 9;

const byte Blueled[] = {28, 26, 24, 22};
const byte Greenled[] = {39, 37, 35, 33, 31, 29, 27};

byte state_greenled [7][7] =
{
  {1, 0, 0, 0, 0, 0, 0},
  {0, 1, 0, 0, 0, 0, 0},
  {0, 0, 1, 0, 0, 0, 0},
  {0, 0, 0, 1, 0, 0, 0},
  {0, 0, 0, 0, 1, 0, 0},
  {0, 0, 0, 0, 0, 1, 0},
  {0, 0, 0, 0, 0, 0, 1},
};

byte state_blueled [4][4] =
{
  {1, 0, 0, 0},
  {0, 1, 0, 0},
  {0, 0, 1, 0},
  {0, 0, 0, 1},
};

const byte Bluebtn[] = {30, 32, 34, 36};
const byte Greenbtn[] = {41, 43, 45, 47, 49, 51, 53};
byte buttonState [] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
byte lastbuttonstate [] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

const byte start = 10;
boolean shifting = true;

const byte adj2 = 8;
const byte adj1 = 7;
const byte nom2 = 6;
const byte nom1 = 5;

int DIN = 2;
int CS =  3;
int CLK = 4;
LedControl lc = LedControl(DIN, CLK, CS, 0);

static unsigned long timer = 0;
unsigned long interval = 50;


void setup()
{
  Serial.begin(9600);
  softwareSerial.begin(9600);
  if (MP3player.begin(softwareSerial))
  {
  Serial.println("MP3 Player ready");
  }
  else
  {
  Serial.println("MP3 Player NOT READY");
  }
  MP3player.volume(27);
  
  //INPUTS
  for (int i = 0; i <= 6; i++)
  {
    pinMode(Greenbtn[i], INPUT_PULLUP);
  }

  for (int i = 0; i <= 3; i++)
  {
    pinMode(Bluebtn[i], INPUT_PULLUP);
  }

  pinMode(start, INPUT_PULLUP);

  pinMode(adj1, INPUT_PULLUP);
  pinMode(adj2, INPUT_PULLUP);
  pinMode(nom1, INPUT_PULLUP);
  pinMode(nom2, INPUT_PULLUP);
  //OUTPUTS
  for (int i = 0; i <= 6; i++)
  {
    pinMode(Greenled[i], OUTPUT);
  }

  for (int i = 0; i <= 3; i++)
  {
    pinMode(Blueled[i], OUTPUT);
  }
  
  lc.shutdown(0, false);
  lc.setIntensity(0, 15);
  

}

//FUNCTIONS

boolean selectedgreenled()//check if there is a choice that has been done
{
  for (int i = 0; i <= 6; i++)
  {
    if (digitalRead(Greenled[i]) == HIGH) true; else false;
  }

}

boolean ledongreen(int x)
{
  if (millis() - timer > interval)
  {
    buttonState[x] = digitalRead(Greenbtn[x]);

    if (buttonState[x] != lastbuttonstate [x])
    {
      timer = millis();
      lastbuttonstate [x] = buttonState[x];

      if (buttonState[x] == LOW)
      {
        for (int i = 0; i <= 6; i++) digitalWrite(Greenled[i], state_greenled [x][i]);
      }
    }
  }
}

boolean ledonblue(int x)
{
  if (millis() - timer > interval)
  {
    buttonState[x + 4] = digitalRead(Bluebtn[x]);

    if (buttonState[x + 4] != lastbuttonstate [x + 4])
    {
      timer = millis();
      lastbuttonstate [x + 4] = buttonState[x + 4];

      if (buttonState[x + 4] == LOW)
      {
        for (int i = 0; i <= 3 ; i++) digitalWrite(Blueled[i], state_blueled [x][i]);
        for (int i = 0; i <= 6; i++) digitalWrite(Greenled[i], LOW); lc.clearDisplay(0);
      }
    }
  }

}

void smile()
{
  byte SMILE[8] = {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C};
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0, i, SMILE[i]);
  }
}

void sad()
{
  byte SAD[8] = {0x3C, 0x42, 0xA5, 0x81, 0x99, 0xA5, 0x42, 0x3C};
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0, i, SAD[i]);
  }

}
void loop()
{
  
  if (digitalRead(start) == LOW)
  {
    lc.clearDisplay(0);
    for (int i = 0; i <= 6; i++) digitalWrite(Greenled[i], LOW);
    tone(buzzer, 1000);
    delay(250);
    noTone(buzzer);
    delay(80);

    shifting = !shifting;
  }

  if (shifting == false)
  {
    
    for (int i = 0; i <= 6; i++) digitalWrite(Greenled[i], LOW);
    for (int i = 0; i <= 3; i++) digitalWrite(Blueled[i], LOW);

    digitalWrite(Blueled[random(0, 4)], HIGH);
    tone(buzzer, 300);
    delay(80);
    noTone(buzzer);
    delay(50);
  }

  ledonblue(0);
  ledonblue(1);
  ledonblue(2);
  ledonblue(3);

  ledongreen(0);
  ledongreen(1);
  ledongreen(2);
  ledongreen(3);
  ledongreen(4);
  ledongreen(5);
  ledongreen(6);

  unsigned pinState = 0;
  for (int n = 0; n <= 6; n++)
    pinState |= digitalRead (Greenled [n]) << n;
    Serial.println (pinState);

  switch (pinState) {
    case 1: //"x" - MS & Adj1 OU MP & Nom1 OU MP & Adj1
      if (digitalRead(Blueled[0]) == HIGH && pinState != 0 )
      {
        smile(); MP3player.play(14);
      }
      else {
        sad();
      }
      break;

    case 2: //"e" -Feminin singulier & Adjectif type 1
      if (digitalRead(Blueled[1]) == HIGH  && pinState != 0)
      {
        smile();MP3player.play(14);
      }
      else {
        sad();
      }
      break;

    case 4: //"es" - Feminin Pluriel & Adjectif type 1
      if (digitalRead(Blueled[3]) == HIGH && digitalRead(adj1) == HIGH && pinState != 0)
      {
        smile();
      }
      else {
        sad();
      }
      break;

    case 8: //"s" - Feminin singulier & Adjectif type 1 OU  Feminin singulier & Nom type 1
      if ((digitalRead(Blueled[2]) == HIGH && (digitalRead(adj2) == HIGH || digitalRead(nom2) == HIGH) || digitalRead(Blueled[3]) == HIGH && (digitalRead(nom1) == HIGH || digitalRead(nom2) == HIGH)) && pinState != 0 )
      {
        smile();
      }
      else {
        sad();
      }
      break;

    case 16: //"se" - Feminin singulier & Adjectif type 2
      if (digitalRead(Blueled[1]) == HIGH && digitalRead(adj2) == HIGH && pinState != 0)
      {
        smile();
      }
      else {
        sad();
      }
      break;

    case 32: //"ses" - Feminin Pluriel & Adjectif type 2
      if (digitalRead(Blueled[3]) == HIGH && digitalRead(adj2) == HIGH && pinState != 0)
      {
        smile();
      }
      else {
        sad();
      }
      break;     

    case 64: //"Rien"
      if ((digitalRead(Blueled[0]) == HIGH && (digitalRead(adj2) == HIGH || digitalRead(nom1) == HIGH || digitalRead(nom2) == HIGH) || digitalRead(Blueled[1]) == HIGH && digitalRead(nom2) == HIGH) && pinState != 0)
      {
        smile();
      }
      else {
        sad();
      }
      break;
  }

}

Why is your code reading pins with LEDs connected to them? They are outputs. If you read those pins, you will get only the last value that was written to them. Should these lines of code be reading pins with buttons connected to them?

Can you understand what I am saying?

Sorry
No

What is your first language? There may be a forum section where you can understand and be understood.

English
may be you can explain to me your point of view with an exemple ?

Here is an explanation video of the working circuit without integration of the audio coding

This pin is set as output. Did you mean to put Bluebtn[0] ?

yes
I think it's better to read the led status then the button status
In fact the Led give you the stable status (it remains on or OFF) not like the Push - button

I am reading your code and trying to understand it. It is not easy, even thought I have been writing code for almost 50 years. The style is confusing and everything seems over-complicated. There are no comments. I don't have time at the moment to digest it fully, maybe later.

Can you please write a step by step explanation of what the code is intended to do?

This function seems strange:

boolean selectedgreenled()//check if there is a choice that has been done
{
  for (int i = 0; i <= 6; i++)
  {
    if (digitalRead(Greenled[i]) == HIGH) true; else false;
  }

}

I'm sure this will not work. The function is declared that it will return a Boolean value (true or false) but it does not do that. The "true;" and "false;" in the if statement will have no effect.

Ah ok
that one is not used anywhere. (I used previousely)
sorry i will delete it

Ok.

Well, I can guess by the pin numbers in your code that you are using an Arduino Mega.

Mega has 4 hardware Serial (UART) ports. One of them is dedicated to uploading your code and printing to Serial Monitor, so that one is not available. But there are 3 others that are available.

If your Arduino has any available hardware Serial ports, you should not be using software serial. It is inferior to hardware Serial.

So I suggest that you remove software serial and use one of the available hardware Serial ports for the DFplayer.

Right now i'm connecting my Dfplayer to RX 19 and TX18 (These are a communication hardware serials on Arduino Mega: see picture below).
I think i don't know how to program or set the Df player correctly via my code
you mention "you remove software serial and use one of the available hardware Serial ports for the DFplayer."
so how should i do on my code?

But you are not using those pins as hardware serial. You are using them with software serial, which uses the pins it is given as normal input/output pins.

The pins you are using are labelled as TX1 and RX1. To use them as hardware serial, use Serial1. For example

  Serial1.begin(9600);
  if (MP3player.begin(Serial1))
1 Like

So is this right now?

#include "Arduino.h"
#include "DFRobotDFPlayerMini.h"
#include <LedControl.h>
#include <SoftwareSerial.h>

//SoftwareSerial Serial1(/*rx =*/19, /*tx =*/18);
DFRobotDFPlayerMini MP3player;

const int buzzer = 9;

const byte Blueled[] = {28, 26, 24, 22};
const byte Greenled[] = {39, 37, 35, 33, 31, 29, 27};

byte state_greenled [7][7] =
{
  {1, 0, 0, 0, 0, 0, 0},
  {0, 1, 0, 0, 0, 0, 0},
  {0, 0, 1, 0, 0, 0, 0},
  {0, 0, 0, 1, 0, 0, 0},
  {0, 0, 0, 0, 1, 0, 0},
  {0, 0, 0, 0, 0, 1, 0},
  {0, 0, 0, 0, 0, 0, 1},
};

byte state_blueled [4][4] =
{
  {1, 0, 0, 0},
  {0, 1, 0, 0},
  {0, 0, 1, 0},
  {0, 0, 0, 1},
};

const byte Bluebtn[] = {30, 32, 34, 36};
const byte Greenbtn[] = {41, 43, 45, 47, 49, 51, 53};
byte buttonState [] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
byte lastbuttonstate [] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

const byte start = 10;
boolean shifting = true;

const byte adj2 = 8;
const byte adj1 = 7;
const byte nom2 = 6;
const byte nom1 = 5;

int DIN = 2;
int CS =  3;
int CLK = 4;
LedControl lc = LedControl(DIN, CLK, CS, 0);

static unsigned long timer = 0;
unsigned long interval = 50;


void setup()
{
  Serial1.begin(9600);
  //Serial.begin(115200);
  
  MP3player.volume(27);
  MP3player.play(14);
  
  //INPUTS
  for (int i = 0; i <= 6; i++)
  {
    pinMode(Greenbtn[i], INPUT_PULLUP);
  }

  for (int i = 0; i <= 3; i++)
  {
    pinMode(Bluebtn[i], INPUT_PULLUP);
  }

  pinMode(start, INPUT_PULLUP);

  pinMode(adj1, INPUT_PULLUP);
  pinMode(adj2, INPUT_PULLUP);
  pinMode(nom1, INPUT_PULLUP);
  pinMode(nom2, INPUT_PULLUP);
  //OUTPUTS
  for (int i = 0; i <= 6; i++)
  {
    pinMode(Greenled[i], OUTPUT);
  }

  for (int i = 0; i <= 3; i++)
  {
    pinMode(Blueled[i], OUTPUT);
  }
  
  lc.shutdown(0, false);
  lc.setIntensity(0, 15);
  

}

//FUNCTIONS

boolean selectedgreenled()//check if there is a choice that has been done
{
  for (int i = 0; i <= 6; i++)
  {
    if (digitalRead(Greenled[i]) == HIGH) true; else false;
  }

}

boolean ledongreen(int x)
{
  if (millis() - timer > interval)
  {
    buttonState[x] = digitalRead(Greenbtn[x]);

    if (buttonState[x] != lastbuttonstate [x])
    {
      timer = millis();
      lastbuttonstate [x] = buttonState[x];

      if (buttonState[x] == LOW)
      {
        for (int i = 0; i <= 6; i++) digitalWrite(Greenled[i], state_greenled [x][i]);
      }
    }
  }
}

boolean ledonblue(int x)
{
  if (millis() - timer > interval)
  {
    buttonState[x + 4] = digitalRead(Bluebtn[x]);

    if (buttonState[x + 4] != lastbuttonstate [x + 4])
    {
      timer = millis();
      lastbuttonstate [x + 4] = buttonState[x + 4];

      if (buttonState[x + 4] == LOW)
      {
        for (int i = 0; i <= 3 ; i++) digitalWrite(Blueled[i], state_blueled [x][i]);
        for (int i = 0; i <= 6; i++) digitalWrite(Greenled[i], LOW); lc.clearDisplay(0);
      }
    }
  }

}

void smile()
{
  byte SMILE[8] = {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C};
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0, i, SMILE[i]);
  }
}

void sad()
{
  byte SAD[8] = {0x3C, 0x42, 0xA5, 0x81, 0x99, 0xA5, 0x42, 0x3C};
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0, i, SAD[i]);
  }

}
void loop()
{
  
  if (digitalRead(start) == LOW)
  {
    lc.clearDisplay(0);
    for (int i = 0; i <= 6; i++) digitalWrite(Greenled[i], LOW);
    tone(buzzer, 1000);
    delay(250);
    noTone(buzzer);
    delay(80);

    shifting = !shifting;
  }

  if (shifting == false)
  {
    
    for (int i = 0; i <= 6; i++) digitalWrite(Greenled[i], LOW);
    for (int i = 0; i <= 3; i++) digitalWrite(Blueled[i], LOW);

    digitalWrite(Blueled[random(0, 4)], HIGH);
    tone(buzzer, 300);
    delay(80);
    noTone(buzzer);
    delay(50);
  }

  ledonblue(0);
  ledonblue(1);
  ledonblue(2);
  ledonblue(3);

  ledongreen(0);
  ledongreen(1);
  ledongreen(2);
  ledongreen(3);
  ledongreen(4);
  ledongreen(5);
  ledongreen(6);

  unsigned pinState = 0;
  for (int n = 0; n <= 6; n++)
    pinState |= digitalRead (Greenled [n]) << n;
    Serial.println (pinState);

  switch (pinState) {
    case 1: //"x" - MS & Adj1 OU MP & Nom1 OU MP & Adj1
      if (digitalRead(Blueled[0]) == HIGH && pinState != 0 )
      {
        smile(); MP3player.play(14);
      }
      else {
        sad();
      }
      break;

    case 2: //"e" -Feminin singulier & Adjectif type 1
      if (digitalRead(Blueled[1]) == HIGH  && pinState != 0)
      {
        smile();MP3player.play(14);
      }
      else {
        sad();
      }
      break;

    case 4: //"es" - Feminin Pluriel & Adjectif type 1
      if (digitalRead(Blueled[3]) == HIGH && digitalRead(adj1) == HIGH && pinState != 0)
      {
        smile();
      }
      else {
        sad();
      }
      break;

    case 8: //"s" - Feminin singulier & Adjectif type 1 OU  Feminin singulier & Nom type 1
      if ((digitalRead(Blueled[2]) == HIGH && (digitalRead(adj2) == HIGH || digitalRead(nom2) == HIGH) || digitalRead(Blueled[3]) == HIGH && (digitalRead(nom1) == HIGH || digitalRead(nom2) == HIGH)) && pinState != 0 )
      {
        smile();
      }
      else {
        sad();
      }
      break;

    case 16: //"se" - Feminin singulier & Adjectif type 2
      if (digitalRead(Blueled[1]) == HIGH && digitalRead(adj2) == HIGH && pinState != 0)
      {
        smile();
      }
      else {
        sad();
      }
      break;

    case 32: //"ses" - Feminin Pluriel & Adjectif type 2
      if (digitalRead(Blueled[3]) == HIGH && digitalRead(adj2) == HIGH && pinState != 0)
      {
        smile();
      }
      else {
        sad();
      }
      break;     

    case 64: //"Rien"
      if ((digitalRead(Blueled[0]) == HIGH && (digitalRead(adj2) == HIGH || digitalRead(nom1) == HIGH || digitalRead(nom2) == HIGH) || digitalRead(Blueled[1]) == HIGH && digitalRead(nom2) == HIGH) && pinState != 0)
      {
        smile();
      }
      else {
        sad();
      }
      break;
  }

}

No.

Hi Paul,
back again.
I think that the sketch is working well
I think what i have done already (Sketch from the first post) is similar to your recommendation.
so to make it work, I changed the library from "DFRobotDFPlayerMini.h" to "DFPlayerMini_Fast.h"

the only thing is that it's only playing one mp3 but in "else" state the mp3 cannot be read (Please have a look on screen shot)

#include "SoftwareSerial.h"
#include "DFPlayerMini_Fast.h"
#include <LedControl.h>
static const uint8_t PIN_MP3_TX = 18; 
static const uint8_t PIN_MP3_RX = 19;

SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
DFPlayerMini_Fast MP3player;

const int buzzer = 9;

const byte Blueled[] = {28, 26, 24, 22};
const byte Greenled[] = {39, 37, 35, 33, 31, 29, 27};

byte state_greenled [7][7] =
{
  {1, 0, 0, 0, 0, 0, 0},
  {0, 1, 0, 0, 0, 0, 0},
  {0, 0, 1, 0, 0, 0, 0},
  {0, 0, 0, 1, 0, 0, 0},
  {0, 0, 0, 0, 1, 0, 0},
  {0, 0, 0, 0, 0, 1, 0},
  {0, 0, 0, 0, 0, 0, 1},
};

byte state_blueled [4][4] =
{
  {1, 0, 0, 0},
  {0, 1, 0, 0},
  {0, 0, 1, 0},
  {0, 0, 0, 1},
};

const byte Bluebtn[] = {30, 32, 34, 36};
const byte Greenbtn[] = {41, 43, 45, 47, 49, 51, 53};
byte buttonState [] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
byte lastbuttonstate [] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

const byte start = 10;
boolean shifting = true;

const byte adj2 = 8;
const byte adj1 = 7;
const byte nom2 = 6;
const byte nom1 = 5;

int DIN = 2;
int CS =  3;
int CLK = 4;
LedControl lc = LedControl(DIN, CLK, CS, 0);

static unsigned long timer = 0;
unsigned long interval = 50;


void setup()
{
  Serial.begin(115200);
  softwareSerial.begin(9600);
  if (MP3player.begin(softwareSerial))
  {
  Serial.println("MP3 Player ready");
  }
  else
  {
  Serial.println("MP3 Player NOT READY");
  }
  MP3player.volume(27);
  //MP3player.play(13);
  //MP3player.play(11);
  //MP3player.play(15);
  
  //INPUTS
  for (int i = 0; i <= 6; i++)
  {
    pinMode(Greenbtn[i], INPUT_PULLUP);
  }

  for (int i = 0; i <= 3; i++)
  {
    pinMode(Bluebtn[i], INPUT_PULLUP);
  }

  pinMode(start, INPUT_PULLUP);

  pinMode(adj1, INPUT_PULLUP);
  pinMode(adj2, INPUT_PULLUP);
  pinMode(nom1, INPUT_PULLUP);
  pinMode(nom2, INPUT_PULLUP);
  //OUTPUTS
  for (int i = 0; i <= 6; i++)
  {
    pinMode(Greenled[i], OUTPUT);
  }

  for (int i = 0; i <= 3; i++)
  {
    pinMode(Blueled[i], OUTPUT);
  }
  
  lc.shutdown(0, false);
  lc.setIntensity(0, 15);
  

}

//FUNCTIONS

/*boolean selectedgreenled()//check if there is a choice that has been done
{
  for (int i = 0; i <= 6; i++)
  {
    if (digitalRead(Greenled[i]) == HIGH) true; else false;
  }

}
*/
boolean ledongreen(int x)
{
  if (millis() - timer > interval)
  {
    buttonState[x] = digitalRead(Greenbtn[x]);

    if (buttonState[x] != lastbuttonstate [x])
    {
      timer = millis();
      lastbuttonstate [x] = buttonState[x];

      if (buttonState[x] == LOW)
      {
        for (int i = 0; i <= 6; i++) digitalWrite(Greenled[i], state_greenled [x][i]);
                
      }
    }
  }
}

boolean ledonblue(int x)
{
  if (millis() - timer > interval)
  {
    buttonState[x + 4] = digitalRead(Bluebtn[x]);

    if (buttonState[x + 4] != lastbuttonstate [x + 4])
    {
      timer = millis();
      lastbuttonstate [x + 4] = buttonState[x + 4];

      if (buttonState[x + 4] == LOW)
      {
        for (int i = 0; i <= 3 ; i++) digitalWrite(Blueled[i], state_blueled [x][i]);
        for (int i = 0; i <= 6; i++) digitalWrite(Greenled[i], LOW); lc.clearDisplay(0);
      }
    }
  }

}

void smile()
{
  byte SMILE[8] = {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C};
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0, i, SMILE[i]);
  }
}

void sad()
{
  byte SAD[8] = {0x3C, 0x42, 0xA5, 0x81, 0x99, 0xA5, 0x42, 0x3C};
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0, i, SAD[i]);
  }

}
void loop()
{
  
  if (digitalRead(start) == LOW)
  {
    lc.clearDisplay(0);
    for (int i = 0; i <= 6; i++) digitalWrite(Greenled[i], LOW);
    tone(buzzer, 1000);
    delay(250);
    noTone(buzzer);
    delay(80);

    shifting = !shifting;
  }

  if (shifting == false)
  {
    
    for (int i = 0; i <= 6; i++) digitalWrite(Greenled[i], LOW);
    for (int i = 0; i <= 3; i++) digitalWrite(Blueled[i], LOW);

    digitalWrite(Blueled[random(0, 4)], HIGH);
    tone(buzzer, 300);
    delay(80);
    noTone(buzzer);
    delay(50);
  }

  ledonblue(0);
  ledonblue(1);
  ledonblue(2);
  ledonblue(3);

  ledongreen(0);
  ledongreen(1);
  ledongreen(2);
  ledongreen(3);
  ledongreen(4);
  ledongreen(5);
  ledongreen(6);

  unsigned pinState = 0;
  for (int n = 0; n <= 6; n++)
    pinState |= digitalRead (Greenled [n]) << n;
    Serial.println (pinState);

  switch (pinState) {
    case 1: //"x" - MS & Adj1 OU MP & Nom1 OU MP & Adj1
      if ((digitalRead(Blueled[0]) == HIGH && digitalRead(adj1) == HIGH || digitalRead(Blueled[2]) == HIGH && (digitalRead(nom1) == HIGH || digitalRead(adj1) == HIGH)) && pinState != 0 )
      {
        smile(); if (digitalRead(Greenbtn[0]) == LOW) MP3player.play(1);
      }
      else {
        sad();//if (digitalRead(Greenbtn[0]) == LOW) MP3player.play(1);
      }
      break;

    case 2: //"e" -Feminin singulier & Adjectif type 1
      if (digitalRead(Blueled[1]) == HIGH && (digitalRead(adj1) == HIGH || digitalRead(nom1) == HIGH) && pinState != 0)
      {
        smile();if (digitalRead(Greenbtn[1]) == LOW) MP3player.play(1);
      }
      else {
        sad();//if (digitalRead(Greenbtn[1]) == LOW) MP3player.play(1);
      }
      break;

    case 4: //"es" - Feminin Pluriel & Adjectif type 1
      if (digitalRead(Blueled[3]) == HIGH && digitalRead(adj1) == HIGH && pinState != 0)
      {
        smile();if (digitalRead(Greenbtn[2]) == LOW) MP3player.play(1);
      }
      else {
        sad();//if (digitalRead(Greenbtn[2]) == LOW) MP3player.play(3);
      }
      break;

    case 8: //"s" - Feminin singulier & Adjectif type 1 OU  Feminin singulier & Nom type 1
      if ((digitalRead(Blueled[2]) == HIGH && (digitalRead(adj2) == HIGH || digitalRead(nom2) == HIGH) || digitalRead(Blueled[3]) == HIGH && (digitalRead(nom1) == HIGH || digitalRead(nom2) == HIGH)) && pinState != 0 )
      {
        smile(); if (digitalRead(Greenbtn[3]) == LOW) MP3player.play(1);
      }
      else {
        sad();//if (digitalRead(Greenbtn[3]) == LOW) MP3player.play(4);
      }
      break;

    case 16: //"se" - Feminin singulier & Adjectif type 2
      if (digitalRead(Blueled[1]) == HIGH && digitalRead(adj2) == HIGH && pinState != 0)
      {
        smile(); if (digitalRead(Greenbtn[4]) == LOW) MP3player.play(1);
      }
      else {
        sad();//if (digitalRead(Greenbtn[4]) == LOW) MP3player.play(5);
      }
      break;

    case 32: //"ses" - Feminin Pluriel & Adjectif type 2
      if (digitalRead(Blueled[3]) == HIGH && digitalRead(adj2) == HIGH && pinState != 0)
      {
        smile();if (digitalRead(Greenbtn[5]) == LOW) MP3player.play(1);
      }
      else {
        sad();//if (digitalRead(Greenbtn[5]) == LOW) MP3player.play(6);
      }
      break;     

    case 64: //"Rien"
      if ((digitalRead(Blueled[0]) == HIGH && (digitalRead(adj2) == HIGH || digitalRead(nom1) == HIGH || digitalRead(nom2) == HIGH) || digitalRead(Blueled[1]) == HIGH && digitalRead(nom2) == HIGH) && pinState != 0)
      {
        smile();if (digitalRead(Greenbtn[6]) == LOW) MP3player.play(1);
        
      }
      else {
        sad();
       if (digitalRead(Greenbtn[0]) == LOW) MP3player.play(6);

       }
      break;
  }

}

Please do not post screen shots of code. Copy the code and paste it into your post between code tags. It is easier to read that way.

case 64: //"Rien"
      if ((digitalRead(Blueled[0]) == HIGH && (digitalRead(adj2) == HIGH || digitalRead(nom1) == HIGH || digitalRead(nom2) == HIGH) || digitalRead(Blueled[1]) == HIGH && digitalRead(nom2) == HIGH) && pinState != 0)
      {
        smile(); 
        if (digitalRead(Greenbtn[6]) == LOW) MP3player.play(1);
        
      }
      else {
        sad(); 
        if (digitalRead(Greenbtn[0]) == LOW) MP3player.play(6);
        
        }
      break;
1 Like