Hello friends
I am making a project using Arduino that has servo to rotate and play sound simultaneously in one sketch. I have done it separately and now I want to combine them, I have done a lot of efforts but It didn't work at all when I combine them together. The project is that I have 3 file on my SDD card and the it is parrot sound and a servo on the mouth of the parrot now when the part opens the mouth I want it to play one sound file and then the other and soon. Can someone give me a hint or help me please, thanks.
Here are my codes:
Servo code:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
myservo.attach(6); // attaches the servo on pin 6 to the servo object
}
void loop() {
for (pos = 165; pos >=65; pos -=1) { // goes from 180 degrees to 0 degrees
myservo.write(pos);
delay(15);
}
for (pos = 65; pos <= 165; pos +=1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos);
delay(20);
}
}
and sound code
/*
Example: Control a WTV020-SD-16P module to play voices from an Arduino board.
Created by Diego J. Arevalo, August 6th, 2012.
Released into the public domain.
*/
#include <Wtv020sd16p.h>
int resetPin = 2; // The pin number of the reset pin.
int clockPin = 3; // The pin number of the clock pin.
int dataPin = 4; // The pin number of the data pin.
int busyPin = 5; // The pin number of the busy pin.
Wtv020sd16p wtv020sd16p(resetPin,clockPin,dataPin,busyPin);
void setup() {
//Initializes the module.
wtv020sd16p.reset();
}
void loop() {
//Plays synchronously an audio file. Busy pin is used for this method.
wtv020sd16p.playVoice(0);
//Plays asynchronously an audio file.
wtv020sd16p.asyncPlayVoice(1);
//Plays audio file number 1 during 2 seconds.
delay(2000);
//Pauses audio file number 1 during 2 seconds.
wtv020sd16p.pauseVoice();
delay(2000);
//Resumes audio file number 1 during 2 seconds.
wtv020sd16p.pauseVoice();
delay(1000);
//Stops current audio file playing.
wtv020sd16p.stopVoice();
//Plays synchronously an audio file. Busy pin is used for this method.
wtv020sd16p.asyncPlayVoice(2);
delay(2000);
//Mutes audio file number 2 during 2 seconds.
// wtv020sd16p.mute();
// delay(1000);
// //Unmutes audio file number 2 during 2 seconds.
// wtv020sd16p.unmute();
// delay(2000);
//Stops current audio file playing.
wtv020sd16p.pauseVoice();
delay(2000);
//Resumes audio file number 1 during 2 seconds.
wtv020sd16p.pauseVoice();
delay(1000);
wtv020sd16p.stopVoice();
wtv020sd16p.asyncPlayVoice(3);
delay(2000);
wtv020sd16p.pauseVoice();
delay(2000);
//Resumes audio file number 1 during 2 seconds.
wtv020sd16p.pauseVoice();
delay(1000);
wtv020sd16p.stopVoice();
}
sound_WTV.ino (1.74 KB)