Hello. I have been having some problems using the Arduino Waveshield, and I've reduced them to something wrong with my switch case statement - I want it to play different sounds when I feed it numbers via the serial monitor in the IDE, but it's not even getting to the switch case - I know this because I included a default, which constantly spits out the line "dogs and cats", and doesn't stop when I send one of the number keys into the serial port.
I am aware I am probably doing something really simple worng - precisely what that thing might be is what I hope to ascertain with this post
Here is my code:
#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"
AF_Wave card;
File f;
Wavefile wave;
#define redled 9
void setup() {
// set up serial port
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(redled, OUTPUT);
// open memory card
if (!card.init_card()) {
putstring_nl("Card init failed!"); return;
}
if (!card.open_partition()) {
putstring_nl("No partition!"); return;
}
if (!card.open_filesys()) {
putstring_nl("Couldn't open filesys"); return;
}
if (!card.open_rootdir()) {
putstring_nl("Couldn't open dir"); return;
}
}
void loop() {
int c = 0;
if (Serial.available()) {
c = Serial.read();
//Serial.println(c, BYTE);
}
switch (c) {
case 1:
playfile("1.WAV")
break;
case 2:
playfile("2.WAV");
break;
case 3:
playfile("3.WAV");
break;
case 4:
playfile("4.WAV");
break;
case 5:
playfile("5.WAV");
break;
case 6:
playfile("6.WAV");
default:
Serial.println("dogs and cats");
}
}
void playfile(char *name) {
Serial.print("bang");
// stop any file already playing
if (wave.isplaying) {
wave.stop();
card.close_file(f);
}
// close file if open
// play specified file
f = card.open_file(name);
if (f && wave.create(f)) {
wave.play();
}
}