The second and third while and if are not working but the first while and if do work. Am I doing something wrong?
#include <DFMiniMp3.h>
int sw1 = 3;
int sw2 = 4;
int sw3 = 5;
class Mp3Notify
{
public:
static void OnError(uint16_t errorCode)
{
// see DfMp3_Error for code meaning
Serial.println();
Serial.print("Com Error ");
Serial.println(errorCode);
}
static void OnPlayFinished(uint16_t globalTrack)
{
Serial.println();
Serial.print("Play finished for #");
Serial.println(globalTrack);
}
static void OnCardOnline(uint16_t code)
{
Serial.println();
Serial.print("Card online ");
Serial.println(code);
}
static void OnCardInserted(uint16_t code)
{
Serial.println();
Serial.print("Card inserted ");
Serial.println(code);
}
static void OnCardRemoved(uint16_t code)
{
Serial.println();
Serial.print("Card removed ");
Serial.println(code);
}
};
DFMiniMp3<HardwareSerial, Mp3Notify> mp3(Serial); //Create the UART connection to the module
void setup()
{
//3 push buttons with pullups
pinMode(sw1, INPUT); //Define each button as input with pullup
pinMode(sw2, INPUT);
pinMode(sw3, INPUT);
digitalWrite (sw1, HIGH); //12 Votls supply set to off state
digitalWrite (sw2, HIGH); //5 Votls supply set to off state
digitalWrite (sw3, HIGH); //3 Votls supply set to off state
Serial.begin(9600);
mp3.begin(); //Start communication with the DFplayer module
uint16_t volume = mp3.getVolume(); //Get actual volume
mp3.setVolume(30); //Set new volum (max is 30)
uint16_t count = mp3.getTotalTrackCount(); //Get the total tracks on the SD card in case we want to sue this later...
}
//just a fucntion that we use to create delays in "ms"
//without using the delay() function
void waitMilliseconds(uint16_t msWait)
{
uint32_t start = millis();
while ((millis() - start) < msWait)
{
// calling mp3.loop() periodically allows for notifications
// to be handled without interrupts
mp3.loop();
delay(1);
}
}
void loop()
{
if (digitalRead(sw1) == LOW)
{
mp3.playMp3FolderTrack(1); // Play audio track 0001
waitMilliseconds(5000); // 1s of delay
while (digitalRead(sw1) == HIGH); // do nothing until state changes
}
if (digitalRead(sw2) == LOW)
{
mp3.playMp3FolderTrack(2); // Play audio track 0002
waitMilliseconds(5000); // 1s of delay
while (digitalRead(sw2) == HIGH); // do nothing until state changes
}
if (digitalRead(sw3) == LOW)
{
mp3.playMp3FolderTrack(3); // Play audio track 0002
waitMilliseconds(5000); // 1s of delay
while (digitalRead(sw3) == HIGH); // do nothing until state changes
}
}