first working prototype
This commit is contained in:
parent
0ac1f18ccc
commit
425bf24d88
Binary file not shown.
48
src/main.cpp
48
src/main.cpp
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue