Hi,
i would like to get some help for my project, which requires me to output an modified audio signal from a SD card to a speaker.
firstly i need to be able to get the audio signal played out through the speaker. i've got the audio file in my SD card (.WAV file), but the circuit doesnt seem to work. i suspect its the programming code, can someone help me with this? when i connect the arduino to my laptop, the circuit doesnt seem to have power running through it.
i followed this:
the code used:
#include <SD.h>
#include <TMRpcm.h>
TMRpcm tmrpcm;
File root;
File entry;
// ---------------------------------------------------------------------------------
// set chipSelect to '10' if using the $2 SD card module or '4' if using the
// Ethernet shield's microSD card instead.
const int chipSelect = 10;
// ---------------------------------------------------------------------------------
const int oldCard = SPI_HALF_SPEED;
const int newCard = SPI_QUARTER_SPEED;
// ---------------------------------------------------------------------------------
// set cardType to 'oldCard' if using an old SD card (more than a few years old) or
// to 'newCard' if using a newly-purchase Class-4 card.
int cardType = newCard;
// ---------------------------------------------------------------------------------
int wasPlaying = 0;
int inSwitch = 7;
int finished = 0;
int start = 0;
int pauseOn = 0;
unsigned long timeDiff = 0;
unsigned long timePress = 0;
void setup() {
Serial.begin(9600);
Serial.print("\nInitializing SD card...");
pinMode(chipSelect, OUTPUT);
if (!SD.begin(chipSelect,cardType)) {
Serial.println("failed!");
return;
}
Serial.println("done.");
tmrpcm.speakerPin = 9;
pinMode(inSwitch,INPUT_PULLUP);
digitalWrite(inSwitch,HIGH);
root = SD.open("/");
}
void loop(void) {
if(!tmrpcm.isPlaying() && wasPlaying == 1) {
tmrpcm.stopPlayback();
playNext();
}
if (millis() - timeDiff > 50) { // check switch every 100ms
timeDiff = millis(); // get current millisecond count
if(digitalRead(inSwitch) == LOW) {
if(start==0) {
start=1;
playNext();
delay(200);
} else {
timePress = millis();
while(digitalRead(inSwitch)==LOW) {
delay(50);
}
if (millis() - timePress < 1000 && start == 1) {
tmrpcm.pause();
if (pauseOn == 0) {
pauseOn = 1;
} else {
pauseOn = 0;
}
}
if (millis() - timePress > 1000 && start == 1) {
if (pauseOn == 1) {pauseOn = 0; tmrpcm.pause();}
tmrpcm.stopPlayback();
timePress = millis();
if (finished == 0) {
playNext();
} else {
finished = 0;
Serial.println("Restarting.");
root.rewindDirectory();
playNext();
}
}
}
}
}
}
void playNext() {
entry = root.openNextFile();
if (entry) {
entry.close();
tmrpcm.play(entry.name());
wasPlaying = 1;
} else {
if (wasPlaying == 1) {
Serial.println("Completed playback.");
wasPlaying = 0;
finished = 1;
start = 0;
root.rewindDirectory();
}
}
}