I changed the code so that I can see where it gets stuck:
Seems like its looping 3x and then quits.
#include "Arduino.h"
#include "DFRobotDFPlayerMini.h"
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change:
const long interval = 5000; // interval at which to blink (milliseconds)
DFRobotDFPlayerMini myDFPlayer;
void setup()
{
Serial.println("setup");
pinMode(0,INPUT);
pinMode(1,INPUT);
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
Serial.begin(115200);
Serial1.begin(9600);
myDFPlayer.begin(Serial1);
myDFPlayer.volume(10); //set volume low
delay(100); //wait another 100ms
myDFPlayer.EQ(DFPLAYER_EQ_ROCK); //set EQ as pop
delay(100); //wait another 100ms
myDFPlayer.play(1);
delay(3000);
}
void loop()
{
Serial.println("loop");
unsigned long currentMillis = millis();
if (digitalRead(0)== HIGH)
{
Serial.println("Werbung 1");
myDFPlayer.advertise(1);
}
if (digitalRead(1)== HIGH)
{
Serial.println("Werbung 2");
myDFPlayer.advertise(2);
}
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
myDFPlayer.play(2);
}
17:32:24.021 -> loop
17:32:24.021 -> loop
17:32:24.021 -> Werbung 2
17:32:24.021 -> loop
17:32:24.021 -> Werbung 2
17:32:24.021 -> loop
17:32:24.021 -> Werbung 2