#include <Servo.h> //Include the Servo Library.
// Create servo objects for each servo motor
Servo Servo_North;
Servo Servo_East;
Servo Servo_West;
Servo Servo_South;
int delay_Time = 500;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Enter The Position (0 to 180) for all Servo");
//Attach each Servo Pin to a specific Pin (PMW Pin 3, 5, 6, 9)
Servo_North.attach(3);
Servo_East.attach(5);
Servo_West.attach(6);
Servo_South.attach(9);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>0){
int pos = Serial.parseInt();
//Move all Servo gradually from 0 to 180 degree
if(pos >= 0 && pos <= 180){
Servo_North.write(pos);
Servo_East.write(pos);
Servo_West.write(pos);
Servo_South.write(pos);
delay(delay_Time);
//Provide Feedback to the User
Serial.print("All Servo Set to ");
Serial.print(pos);
Serial.println(" degrees Angle.");
}
else{
// If Input Out of the rangle, notify the user
Serial.println("Invallid Position! Please Enter a Valude between 0 t0 180");
}
// Clear any remaining characters in the serial buffer
while (Serial.available() > 0) {
Serial.read();
}
}
}