I have gotten everything working after I read that the Wave shield is already playing the song asynchronously. The thresholds will be modified of course, but the ones in my final code show that it works.
#include <WaveHC.h>
#include <WaveUtil.h>
#include <avr/io.h>
#include <avr/interrupt.h>
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 volumes root directory
FatReader file; // This object represent the WAV file
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time
const int analogPin = A0; // pin that the sensor is attached to
const int thresholdOne = 5; // 5V threshold
const int thresholdTwo = 3; // 3V threshold
const int thresholdThree = 1; // 1V threshold
float Voltage_Reading = analogPin*(5.0/1023.0);
#define playcomplete(x) ROM_playcomplete(PSTR(x)) // save RAM by using program memory strings
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println(F("Wave test!"));
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
if (!card.init()) {
Serial.println(F("Card init. failed!")); return;
}
// enable optimize read - some cards may timeout. Disable if you're having problems
card.partialBlockRead(true);
// Now we will look for a FAT partition!
uint8_t part;
for (part = 0; part < 5; part++) { // we have up to 5 slots to look in
if (vol.init(card, part))
break; // we found one, lets bail
}
if (part == 5) { // if we ended up not finding one :(
Serial.println(F("No valid FAT partition!")); // Something went wrong, lets print out why
}
// Lets tell the user about what we found
putstring("Using partition ");
Serial.print(part, DEC);
Serial.print(F(", type is FAT"));
Serial.println(vol.fatType(), DEC); // FAT16 or FAT32?
// Try to open the root directory
if (!root.openRoot(vol)) {
Serial.println(F("Can't open root dir!")); // Something went wrong,
}
// Whew! We got past the tough parts.
Serial.println(F("Files found (* = fragmented):"));
// Print out all of the files in all the directories.
root.ls(LS_R | LS_FLAG_FRAGMENTED);
}
void loop() {
int analogValue = analogRead(analogPin); //reads A0 pin resistance
float Voltage_Reading = analogValue*(5.0/1023.0); //converts resistance reading from A0 pin to voltage
Serial.println(Voltage_Reading, DEC); //prints out voltage reading to serial monitor
long time;
if (Voltage_Reading < thresholdThree) {
wave.stop(); //stops any current audio
playfile("PinkCM.WAV"); //plays the specified audio
while (Voltage_Reading < thresholdThree) { //if voltage is within the first threshold range, it will continue
int analogValue = analogRead(analogPin); //reads A0 pin resistance
float Voltage_Reading = analogValue*(5.0/1023.0); //converts resistance reading from A0 pin to voltage
Serial.println(analogValue, DEC); //prints out voltage reading to serial monitor
Serial.println("Pink"); //prints out song name to serial monitor (for testing purposes)
if (Voltage_Reading > thresholdThree) { //if voltage is not within the first threshold range, it will break the while loop
break;}
delay(100);
if (wave.isplaying){} //Does nothing if the audio is playing and breaks the while loop if it has stopped
else{break;}
}
wave.stop();
}
if (Voltage_Reading < thresholdTwo && Voltage_Reading > thresholdThree) {
wave.stop();
playfile("EOTCM.WAV");
while (Voltage_Reading < thresholdTwo && Voltage_Reading > thresholdThree) {
int analogValue = analogRead(analogPin);
float Voltage_Reading = analogValue*(5.0/1023.0);
Serial.println(Voltage_Reading, DEC);
Serial.println("EOT");
if (Voltage_Reading > thresholdTwo || Voltage_Reading < thresholdThree) {
break;}
delay(100);
if (wave.isplaying){}
else{break;}
//Serial.print(".");
}
wave.stop();
}
if (Voltage_Reading > thresholdTwo) {
wave.stop();
playfile("WhatCM.WAV");
while (Voltage_Reading > thresholdTwo) {
int analogValue = analogRead(analogPin);
float Voltage_Reading = analogValue*(5.0/1023.0);
Serial.println(Voltage_Reading, DEC);
Serial.println("What");
if (Voltage_Reading < thresholdTwo) {
break;}
delay(100);
if (wave.isplaying){}
else{break;}
}
wave.stop();
}
}
void playfile(char *name) {
if (!file.open(root, name)) {
Serial.println(F(" Couldn't open file")); return;
}
if (!wave.create(file)) {
Serial.println(F(" Not a valid WAV")); return;
}
// ok time to play!
wave.play();
}
Thanks again to everyone who took the time to read my problem!