Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1).
https://stackoverflow.com/a/71992729
割り込み内で変なことしない方がいい模様
#include <Arduino.h>
#if defined(ARDUINO_ARCH_RP2040)
void setup() {}
void loop() {}
#else
#ifdef ESP32
#include <WiFi.h>
#include "SPIFFS.h"
#else
#include <ESP8266WiFi.h>
#endif
#include "AudioFileSourceSPIFFS.h"
#include "AudioGeneratorMP3.h"
#include "AudioOutputI2S.h"
// To run, set your ESP8266 build to 160MHz, and include a SPIFFS of 512KB or greater.
// Use the "Tools->ESP8266/ESP32 Sketch Data Upload" menu to write the MP3 to SPIFFS
// Then upload the sketch normally.
// pno_cs from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html
struct Button {
const uint8_t PIN;
const char *filename;
bool pressed;
};
Button button = {17, "/pno-cs.mp3", false};
void play_audio(const char *);
void stop_audio();
void ARDUINO_ISR_ATTR isr(void* arg) {
Button* s = static_cast<Button*>(arg);
s->pressed = true;
}
AudioGeneratorMP3 *mp3;
AudioFileSourceSPIFFS *file;
AudioOutputI2S *out;
void setup()
{
WiFi.mode(WIFI_OFF);
Serial.begin(115200);
delay(1000);
SPIFFS.begin();
Serial.printf("Sample MP3 playback begins...\n");
// setup audio
audioLogger = &Serial;
out = new AudioOutputI2S();
mp3 = new AudioGeneratorMP3();
//mp3->begin(id3, out);
// setup button
pinMode(button.PIN, INPUT_PULLUP);
attachInterruptArg(button.PIN, isr, &button, FALLING);
}
void loop()
{
// check button pressed
if (button.pressed){
play_audio(button.filename);
button.pressed = false;
}
if (mp3->isRunning()) {
if (!mp3->loop()) mp3->stop();
} else {
Serial.printf("MP3 done\n");
delay(1000);
}
}
void play_audio(const char *filename){
Serial.printf("play audio");
stop_audio();
file = new AudioFileSourceSPIFFS(filename);
mp3->begin(file, out);
}
void stop_audio(){
if (mp3->isRunning()) {
mp3->stop();
}
}
#endif