I have a very huge problem with my servo.
It should be run DanceServo when the serial monitor shows number 49.
But the servo turns only on the first detecting 49. other only print out the word.
What is the problem with it? Sorry for my bad english.
Here is the code;
#include <SPI.h>
#include <pcmConfig.h>
#include <pcmRF.h>
#include <TMRpcm.h>
#include <SD.h>
#include <Servo.h>
#define servoPin 5
#define SD_ChipSelectPin 4
Servo myservo;
int md;
int val;
int angle = 0;
int potpin = A0;
TMRpcm tmrpcm;
void setup() {
myservo.attach(servoPin);
Serial.begin(9600);
tmrpcm.speakerPin=9;
tmrpcm.setVolume(5);
if(!SD.begin(SD_ChipSelectPin)){
Serial.println("SD fails");
return;
}
}
void DanceServo()
{
myservo.write(90);
Serial.println("turn 90");
delay(1000);
myservo.write(180);
Serial.println("turn 180");
delay(1000);
myservo.write(0);
Serial.println("turn 0");
delay(1000);
}
void RandomMusic()
{
int Music = random(3);
switch(Music)
{
case 0 :
tmrpcm.stopPlayback();
tmrpcm.play("1.wav");
Serial.println("1v");
break;
case 1 :
tmrpcm.stopPlayback();
tmrpcm.play("2.wav");
Serial.println("2v");
break;
case 2 : tmrpcm.stopPlayback();
tmrpcm.play("3.wav");
Serial.println("3v");
break;
}
void loop() {
while(1)
{
if(Serial.available()>0)
{
md=Serial.read();
switch(md)
{
case 49:
Serial.println("Got it");
DanceServo();
break;
}