first working prototype

This commit is contained in:
Stefan Ostermann 2023-05-29 22:44:45 +02:00
parent 0ac1f18ccc
commit 425bf24d88
2 changed files with 35 additions and 13 deletions

BIN
data/ex2.mp3 Normal file

Binary file not shown.

View File

@ -11,13 +11,25 @@
AudioGeneratorMP3 *mp3;
AudioFileSourceSPIFFS *file;
AudioOutputI2SNoDAC *out;
AudioOutputI2S *out;
unsigned long lastStart = 0;
const int startDelay = 250;
void initMp3File() {
file = new AudioFileSourceSPIFFS("/ex2.mp3");
out = new AudioOutputI2S();
mp3 = new AudioGeneratorMP3();
}
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(D3, INPUT_PULLUP);
// WiFiManager
// Local intialization. Once its business is done, there is no need to keep it around
@ -47,27 +59,37 @@ void setup()
SPIFFS.begin();
Serial.println("beginning mp3 setup...");
file = new AudioFileSourceSPIFFS("/ex.mp3");
out = new AudioOutputI2SNoDAC();
mp3 = new AudioGeneratorMP3();
if (!mp3->begin(file, out)) {
Serial.println("could not play file.");
}
initMp3File();
}
void loop()
{
//Serial.print(digitalRead(D2));
if (digitalRead(D3)==LOW) {
unsigned long now = millis();
Serial.print("LOW");
if (now-lastStart>startDelay) {
if (mp3->isRunning()) {
mp3->stop();
}
initMp3File();
mp3->begin(file,out);
Serial.print("started.");
lastStart=now;
}
}
if (mp3->isRunning())
{
if (!mp3->loop())
mp3->stop();
}
else
{
Serial.printf("MP3 done\n");
delay(1000);
}
}