Hi,
I have a small problem with my program. I wrote this program, trying to have 4 servo connected to Arduino. The problem I have is the servos are not responding to the program. I was wondering if there is a problem with my program. Any help would be appreciated.
#include "Servo.h"
int position=0; //position of piston pin from crank center. We initialize it to 0
int servo1PosChord1=60;
int servo2PosChord1=79;
int servo3PosChord1=180;
int servo4PosChord1=40;
int servo1PosChord2=60;
int servo2PosChord2=79;
int servo3PosChord2=180;
int servo4PosChord2=0;
int servo1PosChord3=60;
int servo2PosChord3=79;
int servo3PosChord3=169;
int servo4PosChord3=0;
int servo1PosChord4=90;
int servo2PosChord4=0;
int servo3PosChord4=85;
int servo4PosChord4=40;
int chord=0; //this is how we keep track which chord we are in
const int servoDelay=1000;
Servo myservo1; //servo 1
Servo myservo2; //servo 2
Servo myservo3; //servo 3
Servo myservo4; //servo 4
void setup(){
myservo1.attach(3); //attach each servo to the appropriate pins
myservo2.attach(6);
myservo3.attach(9);
myservo4.attach(10);
//use this to test the code
Serial.begin(9600);
//Use this to sound the chords once
for (chord=1; chord<=4; chord +=1){
Serial.print("Chord ");
Serial.println(chord);
switch(chord){
case 1:
Serial.print("Case 1");
Serial.println();
myservo1.write(servo1PosChord1);
myservo2.write(servo2PosChord1);
myservo3.write(servo3PosChord1);
myservo4.write(servo4PosChord1);
delay(servoDelay);
break;
case 2:
Serial.print("Case 2");
Serial.println();
myservo1.write(servo1PosChord2);
myservo2.write(servo2PosChord2);
myservo3.write(servo3PosChord2);
myservo4.write(servo4PosChord2);
delay(servoDelay);
break;
case 3:
Serial.print("Case 3");
Serial.println();
myservo1.write(servo1PosChord3);
myservo2.write(servo2PosChord3);
myservo3.write(servo3PosChord3);
myservo4.write(servo4PosChord4);
delay(servoDelay);
break;
case 4:
Serial.print("Case 4");
Serial.println();
myservo1.write(servo1PosChord4);
myservo2.write(servo2PosChord4);
myservo3.write(servo3PosChord4);
myservo4.write(servo4PosChord4);
delay(servoDelay);
break;
default:
break;
}
}
}
void loop(){ //use this if you want unlimited loop on the chord
for (chord=1; chord<=4; chord +=1){
Serial.print("Chord ");
Serial.println(chord);
switch(chord){
case 1:
Serial.print("Case 1");
Serial.println();
myservo1.write(servo1PosChord1);
myservo2.write(servo2PosChord1);
myservo3.write(servo3PosChord1);
myservo4.write(servo4PosChord1);
delay(servoDelay);
break;
case 2:
Serial.print("Case 2");
Serial.println();
myservo1.write(servo1PosChord2);
myservo2.write(servo2PosChord2);
myservo3.write(servo3PosChord2);
myservo4.write(servo4PosChord2);
delay(servoDelay);
break;
case 3:
Serial.print("Case 3");
Serial.println();
myservo1.write(servo1PosChord3);
myservo2.write(servo2PosChord3);
myservo3.write(servo3PosChord3);
myservo4.write(servo4PosChord3);
delay(servoDelay);
break;
case 4:
Serial.print("Case 4");
Serial.println();
myservo1.write(servo1PosChord4);
myservo2.write(servo2PosChord4);
myservo3.write(servo3PosChord4);
myservo4.write(servo4PosChord4);
delay(servoDelay);
break;
default:
break;
}
}
return;
}