What I am looking to do is play a list of files from a function so say I press a button the triggers the function and plays a file, press a different button and a different file plays. I will also need to string a few files together to play one after the other.
Here is what I have so far:
Code: Select all
#include "Audio.h"
#include "SD.h"
#include "FS.h"
// Digital I/O used
#define SD_CS 5
#define SPI_MOSI 23
#define SPI_MISO 19
#define SPI_SCK 18
#define I2S_DOUT 25
#define I2S_BCLK 27
#define I2S_LRC 26
#define buttonPin 2
#define ledPin 0
int buttonState = 0;
Audio audio;
void setup() {
pinMode(SD_CS, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(SD_CS, HIGH);
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
Serial.begin(115200);
SD.begin(SD_CS);
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(10); // 0...21
audio.connecttoFS(SD, "100.wav");
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
playsound();
} else {
digitalWrite(ledPin, LOW);
}
}
void playsound()
{
audio.loop();
}
Code: Select all
void setup() {
pinMode(SD_CS, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(SD_CS, HIGH);
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
Serial.begin(115200);
SD.begin(SD_CS);
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(10); // 0...21
// audio.connecttoFS(SD, "100.wav"); <---Removed
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
playsound();
} else {
digitalWrite(ledPin, LOW);
}
}
void playsound()
{
audio.connecttoFS(SD, "100.wav");
audio.loop();
}
So the main question is how do I get that connecttoFS bit to work outside of the main setup function?
Eventually I want something akin to this:
Code: Select all
void playsound (string file) {
audio.connecttoFS(SD, file);
audio.loop();
}
Code: Select all
playsound ("Hello.wav");
playsound ("World.wav");
if buttonPressed=1 {
playsound ("Foo.wav");
} elseif buttonPressed=2 {
playsound ("bar.wav");
}
I feel like this should be a stupid simple task, but I am having a heck of a time working this out.