mirror of
https://github.com/Crocmagnon/buzzer.git
synced 2024-12-26 16:01:49 +01:00
Trigger play when button press
This commit is contained in:
parent
372cf830ae
commit
0b2a0c702a
1 changed files with 15 additions and 1 deletions
16
src/main.cpp
16
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue