Trigger play when button press

This commit is contained in:
Gabriel Augendre 2023-01-02 15:42:39 +01:00
parent 372cf830ae
commit 0b2a0c702a

View file

@ -12,17 +12,25 @@
#define I2S_LRC 26
#define LED 2
#define BUTTON 18
String selectedFile = "";
AsyncWebServer server(80);
Audio audio;
void onPlay(AsyncWebServerRequest *request)
byte buttonLastState = HIGH;
void play()
{
String path = "/music/" + selectedFile;
Serial.println("Playing file: " + path);
audio.connecttoFS(SPIFFS, path.c_str());
}
void onPlay(AsyncWebServerRequest *request)
{
play();
request->send(200);
}
@ -68,6 +76,8 @@ void setup()
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
pinMode(BUTTON, INPUT_PULLUP);
// Setup SPIFFS
if (!SPIFFS.begin())
{
@ -128,4 +138,8 @@ void setup()
void loop()
{
byte buttonCurrentState = digitalRead(BUTTON);
if (buttonCurrentState == LOW && buttonLastState == HIGH)
play();
buttonLastState = buttonCurrentState;
}