Sketch com NRF24L01 + DFPlayerMini - ERRO

I'm designing 2 sketch's for the following function:

The first device waits for a button to be clicked so that it can send this receipt to a second device.

However on this second device I also need to run an mp3 file for that I'm using a DFPlayerMini, however, by including the library and the necessary codes, it causes a bottleneck.

Could anyone help me?

Sketch1:

#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>

RF24 radio(9, 10);

const byte endereco[6] = "1node";
int ledTransmissor = 2;
int botaoTransmissor = 3;
bool estado = LOW;
bool enviado1, enviado2;

void setup() {

  pinMode(ledTransmissor, OUTPUT);
  pinMode(botaoTransmissor, INPUT_PULLUP);

  radio.begin();
  radio.setPALevel(RF24_PA_MIN);
  radio.setChannel(82);
  radio.openWritingPipe(endereco);
  radio.openReadingPipe(0, endereco);
  radio.stopListening();
}

void loop() {
  if (!digitalRead(botaoTransmissor) == HIGH) {
    estado = !estado;
  }

  if (estado == HIGH) {
    enviado1 = HIGH;
    while(radio.write(&enviado1, sizeof(enviado1)))
    radio.startListening();
    if (radio.available()) {
      radio.read(&enviado2, sizeof(enviado2));
      if (enviado2 == HIGH) {
        digitalWrite(ledTransmissor, HIGH);
        delay(5000);
        digitalWrite(ledTransmissor, LOW);
      }
    }
    radio.stopListening();
    enviado1 = LOW;
    estado = LOW;
  }
}

Sketch2:

#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#define pinRx 3
#define pinTx 4
#define volumeMP3 5

#define DEBUG
SoftwareSerial playerMP3Serial(pinRx, pinTx);

DFRobotDFPlayerMini playerMP3;

RF24 radio(9, 10);

const byte endereco[6] = "1node";
int ledReceptor = 2;
bool enviado1, enviado2;

void setup() {

  Serial.begin(9600);
  playerMP3Serial.begin(9600);
  
  playerMP3.volume(volumeMP3);

  pinMode(ledReceptor, OUTPUT);

  radio.begin();
  radio.setPALevel(RF24_PA_MIN);
  radio.setChannel(82);
  radio.openWritingPipe(endereco);
  radio.openReadingPipe(0, endereco);
  radio.startListening();

}

void loop() {
  if (radio.available()) {
    radio.read(&enviado1, sizeof(enviado1));
    if (enviado1 == HIGH) {
      enviado2 = HIGH;
      radio.stopListening();
      radio.write(&enviado2, sizeof(enviado2));
        for (int cont = 0; cont < 5; cont++) {
          playerMP3.playFolder(1, 1);
          digitalWrite(ledReceptor, HIGH);
          delay(500);
          digitalWrite(ledReceptor, LOW);
          delay(500);
        }

    }
    radio.startListening();
  }
}

Please post in English in the English language forum sections.

1 Like

I translated using the Cambridge website. Forgiveness.

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