Hello to all! Basically I have my WaveShield responding to my PIR sensor which is fine but I can’t get my LED to light at the same time that the Wav file plays! Have no idea what to do! Thanks for any help :)Goatboy
#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"
int pirPin=6; // Reading from digital pin 6 PIR sensor!
#define LED 7
int val = 0;
AF_Wave card;
File f;
Wavefile wave;
void setup() {
// set up serial port
Serial.begin(9600);
pinMode(pirPin, INPUT);
// set up waveshield pins
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6,INPUT);
pinMode(LED,OUTPUT);
// open memory card...........This part is necessary to set up and read SDcard!
if (!card.init_card()) {
return;
}
if (!card.open_partition()) {
return;
}
if (!card.open_filesys()) {
return;
}
if (!card.open_rootdir()) {
return;
}
}
void loop(){
while (LOW==digitalRead(pirPin)) {;}
playcomplete("WATERW.WAV");
delay(10000);
val = digitalRead(pirPin);
if (val==HIGH) {
digitalWrite(LED,HIGH);
} else {
digitalWrite(LED,LOW);
}
}
void playcomplete(char *name){
playfile(name);
while (wave.isplaying);
card.close_file(f);
}
void playfile(char *name) {
// stop any file already playing
if (wave.isplaying) {
wave.stop();
card.close_file(f);
}
f = card.open_file(name);
if (f && wave.create(f)) {
wave.play();
}
}