- Code: Select all
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
#define songone "SONGONE.WAV"
#define songtwo "SONGTWO.WAV"
#define songthree "SONGTHREE.WAV"
//
//AF_Wave card;
//File f;
//Wavefile wave; // only one!
SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the filesystem on the card
FatReader f; // This holds the information for the file we're play
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time
int wasplaying = 0;
void sdErrorCheck(void) {
if (!card.errorCode()) return;
putstring("\n\rSD I/O error: ");
Serial.print(card.errorCode(), HEX);
putstring(", ");
Serial.println(card.errorData(), HEX);
while(1);
}
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Wave test!");
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
void loop() {
char c, *toplay;
if (Serial.available()) {
c = Serial.read();
Serial.println(byte(c));
if (c == '0') {
toplay = songone;
}
else if (c == '1') {
toplay = songtwo;
}
else if (c == '2') {
toplay = songthree;
}
else {
return;
}
}
}
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
// call our helper to find and play this name
playfile(name);
while (wave.isplaying) {
// do nothing while its playing
}
// now its done playing
}
//
//void ls() {
// char name[13];
// card.reset_dir();
// putstring_nl("Files found:");
// while (1) {
// if (!card.get_next_name_in_dir(name)) {
// card.reset_dir();
// return;
// }
// Serial.println(name);
// }
void playfile(char *name) {
// see if the wave object is currently doing something
if (wave.isplaying) {// already playing something, so stop it!
wave.stop(); // stop it
}
// look in the root directory and open the file
if (!f.open(root, name)) {
putstring("Couldn't open file "); Serial.print(name); return;
}
// OK read the file and turn it into a wave object
if (!wave.create(f)) {
putstring_nl("Not a valid WAV"); return;
}
// ok time to play! start playback
wave.play();
}
It's not responding or playing anything, but it uploads just fine. What it's supposed to do is read the counter value from the other arduino and play the appropriate song. It's not doing that at all, also does anyone know how to make the song stop and change if the counter value suddenly changes?

