My project is to use the wave shield to play a file when the analog value from photocell goes over 900 and does nothing when it falls below 900. The order that files play doesn't matter, I'm thinking I've got to include them in a string and use some "i++" code that I don't really understand. The sensor part of the code is easy enough. I'm using AFWAVE lib file Serial_Control.pde and trying to delete what i don't need. The more I get rid of, the problems I'm encountering. I'm sure it's a few simple lines. I need to get one .WAV file to play after another or in random order(doesn't matter to me), but after trying to write my own or search for examples I keep coming up busted. Any help would be greatly appreciated. And when you see the video of my fridge saying extremely rude, nasty and hilarious statements, the laugh you'll get will be worth helping me out. Simply telling me that I need to use an Array or string isn't enough. I think that's what I need to do, but just don't know how. I'm using Arduino IDE21. Please God members, help me.
similar to this but I can't figure it out. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1281767613
this is what I've got so far. I'm thinking what I need is just a few simple lines that "if(analog > 900) play(i++)" something along these lines but I've tried what I can think of and it hasn't worked yet. thx
#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"
#define HUSKY "HUSKY.WAV"
#define BARN "BARN.WAV"
#define SALAD "SALAD.WAV"
#define ZOOL "ZOOL.WAV"
#define DRUNKPOS "DRUNKPOS.WAV"
#define TRADERJOES "TRADERJOES.WAV"
#define BOTHER "BOTHER.WAV"
#define MIKE1 "MIKE1.WAV"
#define 10MINSAGO "10MINSAGO.WAV"
#define CONDIMENTS "CONDIMENTS.WAV"
AF_Wave card;
File f;
Wavefile wave; // only one!
const int analogInPin = A0; //Pin photocell is connected to
int sensorValue = 0; // Another addition by me
int wasplaying = 0;
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);
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;
}
ls();
// playfile(ONEKHZ);
}
void loop() {
char c, *toplay;
sensorValue = analogRead(analogInPin); //something wrong here or using "char c, *toplay;" is wrong, IDK really
if (Serial.available()) {
c = Serial.read();
Serial.println(c, BYTE);
if (c == "h" ) { //this is where I'm really stuck
toplay = HUSKY; //Compiling this codes gets error
} //ISO C++ forbids comparison between pointer and integer
else if (c == "b" ) {
toplay = BARN;
}
else {
return;
}
if (wave.isplaying) {// already playing something, so stop it!
wave.stop(); // stop it
card.close_file(f);
}
playfile(toplay);
}
wasplaying = wave.isplaying;
}
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) {
f = card.open_file(name);
if (!f) {
putstring_nl("Couldn't open file"); return;
}
if (!wave.create(f)) {
putstring_nl("Not a valid WAV"); return;
}
// ok time to play!
wave.play();
}