diff --git a/src/main.cpp b/src/main.cpp index 4f03d4b..bb48309 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,9 @@ #define I2S_BCLK 27 // connect to DAC pin BCK #define I2S_LRC 25 // connect to DAC pin LCK -#define BTN_START_STOP 17 // Button on D3 and GND +#define BTN_START_STOP 17 // Button on XX and GND +#define BTN_NEXT 16 +#define BTN_PREV 4 #define CS_SDCARD 22 @@ -42,7 +44,7 @@ File mp3File; Audio audio; -uint volume = 12; +uint volume = 8; uint rfid_loop = RFID_LOOP_INTERVAL; @@ -64,6 +66,10 @@ bool asyncStart = false; bool asyncTogglePlayPause = false; +bool asyncNext = false; + +bool asyncPrev = false; + std::map rfid_map{{"67 152 204 14", "01-The_Box_Tops-The_Letter.mp3"}, {"67 175 148 160","068-Der_Schatz_im_Bergsee"}}; @@ -262,6 +268,8 @@ void setup() Serial.begin(115200); pinMode(BTN_START_STOP, INPUT_PULLUP); + pinMode(BTN_NEXT, INPUT_PULLUP); + pinMode(BTN_PREV, INPUT_PULLUP); /* setup the IRQ pin*/ pinMode(IRQ_RFID, INPUT_PULLUP); @@ -436,6 +444,12 @@ void loop() if (asyncTogglePlayPause) { asyncTogglePlayPause = false; togglePlayPause(); + } else if (asyncNext) { + asyncNext = false; + next(); + } else if (asyncPrev) { + asyncPrev = false; + Serial.println("Previous not yet implemented!"); } rfid_loop--; @@ -461,18 +475,27 @@ void loop2(void *parameter) if (buttonPressed(BTN_START_STOP)) { asyncTogglePlayPause = true; + } + if (buttonPressed(BTN_NEXT)) { + asyncNext = true; + } + if (buttonPressed(BTN_PREV)) { + asyncPrev = true; } } } boolean buttonPressed(const uint8_t pin) { + if (digitalRead(pin) == LOW) { + unsigned long now = millis(); if (now - lastStart > startDelay) { lastStart = now; + Serial.println("button pressed."); return true; } }