Please Help!!

Hi All thanks for everyones help so far ive managed to now build the mouth on a board which i operated by a servo for movement.

The only problem is please could someone tell me how to add a sound file which plays at the same time as the servo movement!

Please help!

Heres the code i have so far excluding the wav file

///////// BILLY MOUTH MOVE ///////////////

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 
// a maximum of eight servo objects can be created 

int pos = 0;    // variable to store the servo position 

int calibrationTime = 0;       

long unsigned int lowIn;        

long unsigned int pause = 5000; 

boolean lockLow = true;
boolean takeLowTime; 
/////////////////////////////////////////////////////////////////////////

int pirPin = 11;    ///////////////////// pir sensor pin

/////////////////////////////////////////setup

void setup() 
{ 
  myservo.attach(16);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);
  pinMode(pirPin, INPUT);

  // 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);

  Serial.println("calibrating sensor ");
  for(int i = 0; i < calibrationTime; i++){
    Serial.print(calibrationTime - i);
    Serial.print("-");
    delay(1000);
  }
  Serial.println();
  Serial.println("done");
  while (digitalRead(pirPin) == HIGH) {
    delay(500);
    Serial.print(".");     
  }
  Serial.print("SENSOR ACTIVE");
  delay(1000);


}  
//////////////////////////////////////////////// loop 

void loop() {

  if(digitalRead(pirPin) == HIGH){

    for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 90 degrees 
    {                                  // in steps of 1 degree 
      myservo.write(pos);              // tell servo to go to position in variable 'pos' 
      delay(3);                       // waits 4ms for the servo to reach the position 
    } 
    for(pos = 90; pos>=1; pos-=1)     // goes from 90 degrees to 0 degrees 
    {                                
      myservo.write(pos);              // tell servo to go to position in variable 'pos' 
      delay(3);                       // waits 4ms for the servo to reach the position 
    } 
    if(lockLow){ 

      lockLow = false;           
      Serial.println("---");
      Serial.print("motion detected at ");
      Serial.print(millis()/1000);
      Serial.println(" sec");
      delay(50);
    }        
    takeLowTime = true;
  }

  if(digitalRead(pirPin) == LOW){      

    if(takeLowTime){
      lowIn = millis();
      takeLowTime = false;
    }

    if(!lockLow && millis() - lowIn > pause){ 

      lockLow = true;                       
      Serial.print("motion ended at ");
      Serial.print((millis() - pause)/1000);
      Serial.println(" sec");
      delay(50);
    }
  } 
}

Do you know how you’re going to play the sound file? I mean, do you have / will you get some sort of sound card/shield, or do you intend to play the sound on a PC, or what?

Thanks for the reply Peter im using a wave shield which is the problem

Another djdc23 thread, another crappy title.

Thanks Arrch but if you look its a reply to one of my other post's I'm still stuck and after some advice thats all i ask.

djdc23:
Thanks Arrch but if you look its a reply to one of my other post's

Looks like its own thread to me. If its a reply to one of your other threads, why isn't it in that thread?

djdc23:
Thanks for the reply Peter im using a wave shield which is the problem

Presumably you know which one, and presumably it came with examples demonstrating how to use it. I suggest you run the examples and confirm everything works as you expect, then look at ways to incorporate them into your sketch.

And yes, the title of this thread is very poor and conveys no useful information. I suggest you change it to indicate the nature of your request.

you should post in the same thread as to keep everything together…

looks like yo may have hit the wrong button…

(lets move on)…

O posted in your other thread some advice that might help…

also going to the Adafruit forum where Waveshield & Servo questions are-a-plenty, and searching around, might be a wise choice :slight_smile:

OK well firstly Arrch i apologize if its a different thread i meant it to be the same, I should name it something different you are correct PeterH.

I have been trying to solve this problem for about 2 weeks now and keep going around in circles, I'm also on the Adafruit Forums looking for the same.

The only thing i know for definate is the sketch i posted works absolutely perfect as the movement im after from the servo but as its a servo library it conflicts with the wave shield. Thats why i need help to see if anyone has managed to over come this problem.

Thanks again

From the LadyAda site:

Pins 13, 12, 11 are always used by the SD card

That means pins 6, 7, 8, 9 and the 6 analog in pins (also known as digital i/o pins 14-20) are available

Move your pir to one of the free pins.