diff --git a/src/main.cpp b/src/main.cpp index dcc48bb..b63e968 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; }