for some reason the Serial.println statements do not work. I have now discovered that only 3 wave files can be included in the code. I don't understand why because the WaveHC sample sketch uses 6 wave files. At this point I am just happy I can get the whole project to work even if it isn't what I wanted. Thank you for the input on my post. I am sure I will be posting more soon as I am a graduating electronics student and I am not a programmer. I hope your future input will help me become more of a programmer. Thank you very much. Included below is my functional sketch(except for the Serial.println statements).
#include <SD.h>
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.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 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
void setup()
{
Serial.begin(9600); //Setup Serial
pinMode(14, INPUT); //Assigns analog pins 0-4 as sensor inputs
pinMode(15, INPUT);
pinMode(16, INPUT);
pinMode(17, INPUT);
pinMode(18, INPUT);
pinMode(19, INPUT);
pinMode(6, OUTPUT); //Assigns digital pin 6 as output
pinMode(7, OUTPUT); //Assigns analog pin 7 as output for motor
pinMode(8, OUTPUT); //Assigns digital pin 8 as output for LED cluster 1
pinMode(9, OUTPUT); //Assigns digital pin 9 as output for LED cluster 2
// Set the output pins for the DAC control. This pins are defined in the library
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(10, OUTPUT);
if (!card.init()) { //play with 8 MHz spi (default faster!)
putstring_nl("Card init. failed!"); // Something went wrong, lets print out why
sdErrorCheck();
// while(1); // then 'halt' - do nothing!
}
// 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 :(
putstring_nl("No valid FAT partition!");
sdErrorCheck(); // Something went wrong, lets print out why
//while(1); // then 'halt' - do nothing!
}
// Lets tell the user about what we found
putstring("Using partition ");
Serial.print(part, DEC);
putstring(", type is FAT");
Serial.println(vol.fatType(),DEC); // FAT16 or FAT32?
// Try to open the root directory
if (!root.openRoot(vol)) {
putstring_nl("Can't open root dir!"); // Something went wrong,
// while(1); // then 'halt' - do nothing!
}
// Whew! We got past the tough parts.
putstring_nl("Ready!");
}
void sdErrorCheck(void)
{
if (!card.errorCode())
putstring("\n\rSD I/O error: ");
Serial.print(card.errorCode(), HEX);
putstring(", ");
Serial.println(card.errorData(), HEX);
// while(1);
}
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);
}
// OK read the file and turn it into a wave object
if (!wave.create(f)) {
putstring_nl("Not a valid WAV");
}
// ok time to play! start playback
wave.play();
}
void loop()
{
if(digitalRead(14) == HIGH)
{
// blinky=0;
playfile("howl.WAV");
while (wave.isplaying)
{
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(100);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
delay(100);
}
}
else if(digitalRead(15)==HIGH)
{
playfile("howl.WAV");
while(wave.isplaying)
{
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(100);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
delay(100);
}
}
else if(digitalRead(16)==HIGH)
{
digitalWrite(7,HIGH);
playfile("ghost.WAV");
while(wave.isplaying)
{
digitalWrite(8,HIGH);
delay(70); //set proper delay here for ghost to go to the end
digitalWrite(8,LOW);
delay(70);
}
}
else if(digitalRead(17)==HIGH)
{
digitalWrite(9,HIGH);
delay(60);
digitalWrite(9,LOW);
delay(60);
}
else if(digitalRead(19)==HIGH)
{
playfile("help.WAV");
while(wave.isplaying)
{
digitalWrite(9,HIGH);
delay(120);
digitalWrite(9,LOW);
delay(120);
}
}
delay(10);
}
Message me if you would like to know more about my sensors.