diff --git a/README.md b/README.md index d081473..3b4beb1 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ MISO -> D6 ``` ## TODOs -* Card Reader with SPI. Configure hspi, second SPI channel? +* Card Reader with SPI. Configure hspi, second SPI channel? Or does SD Card + RFID run at the same channel? ![](images/wemos-d1-mini-esp32.png) diff --git a/platformio.ini b/platformio.ini index cbcf853..2879803 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,5 +17,6 @@ lib_deps = me-no-dev/AsyncTCP@^1.1.1 me-no-dev/ESP Async WebServer@^1.2.3 alanswx/ESPAsyncWiFiManager@^0.31 + miguelbalboa/MFRC522@^1.4.10 monitor_speed = 115200 board_build.partitions = huge_app.csv diff --git a/src/globals.h b/src/globals.h index 19ed836..02741b1 100644 --- a/src/globals.h +++ b/src/globals.h @@ -5,5 +5,11 @@ void stop(); void start(); +boolean buttonPressed(const uint8_t pin); + +unsigned long lastStart = 0; + +const int startDelay = 250; + #endif \ No newline at end of file diff --git a/src/helper.h b/src/helper.h index 27de02c..733776e 100644 --- a/src/helper.h +++ b/src/helper.h @@ -2,6 +2,7 @@ #define HELPER_H_ #include +#include "globals.h" struct DirectoryNode { @@ -89,4 +90,6 @@ DirectoryNode* findFirstMP3Node(DirectoryNode* currentNode) { return NULL; } + + #endif /* HELPER_H_ */ \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 06e7b29..22de49a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,12 +9,24 @@ #include "Audio.h" + + + +#include +#include +#include //RFID Reader + +// define pins for RFID +#define CS_RFID 32 +#define RST_RFID 33 + +// Audio DAC #define I2S_DOUT 26 // connect to DAC pin DIN #define I2S_BCLK 27 // connect to DAC pin BCK #define I2S_LRC 25 // connect to DAC pin LCK -#include -#include +#define BTN_START_STOP 17 // Button on D3 and GND + #include "globals.h" #include "WebContent.h" @@ -24,9 +36,7 @@ File root; File mp3File; -unsigned long lastStart = 0; -const int startDelay = 250; Audio audio; @@ -42,6 +52,8 @@ boolean blockState = false; + + void playNextMp3() { blockState = true; @@ -161,7 +173,7 @@ void setup() // put your setup code here, to run once: Serial.begin(115200); - pinMode(D3, INPUT_PULLUP); + pinMode(BTN_START_STOP, INPUT_PULLUP); // first parameter is name of access point, second is the password AsyncWiFiManager wifiManager(&server, &dns); @@ -219,13 +231,28 @@ void loop() { audio.loop(); - if (digitalRead(D3) == LOW) + + if (buttonPressed(BTN_START_STOP)) { + if (audio.isRunning()) { + stop(); + } else { + start(); + } + } + +} + +boolean buttonPressed(const uint8_t pin) { + if (digitalRead(pin) == LOW) { unsigned long now = millis(); if (now - lastStart > startDelay) { - playNextMp3(); + lastStart = now; + return true; } } -} \ No newline at end of file + return false; +} +