#include <Servo.h>
Servo servo1; // create servo object to control a servo
Servo servo2; // twelve servo objects can be created on most boards
int input = 0;
int pos = 0; // variable to store the servo position
int servo = 0;
void setup() {
servo1.attach(13); // attaches the servo on pin 13 to the servo object
servo2.attach(12); // attaches the servo on pin 12 to the servo object
Serial.begin(9600);
servo1.write(0);
servo2.write(0);
}
void loop() {
if (Serial.available() > 0) {
// read the incoming byte:
input = Serial.parseInt();//You must introduce the degrees that you
//want the servo moves + the number of servo
//e.g.input = 902 moves servo2 90 degrees
}
pos = input / 10; //Separate degrees from input
servo = input % 10;//Separate the number of servo from input
if (servo == 1) {
servo1.write(pos); // tell servo1 to go to position in variable 'pos'
}
if (servo == 2) {
servo2.write(pos); // tell servo2 to go to position in variable 'pos'
}
}