servotest.ino

#include <Servo.h> // inlcude library for servos

// init servos 
#define SERVO_PIN_1 9
#define SERVO_PIN_2 10
Servo servo1;
Servo servo2;

void setup() {

  // initialize serial port
  Serial.begin(9600);
  
  // leonardo workaround waiting for serial port to be ok
  while(!Serial)delay(1);

  // init servos
  Serial.print("Init Servos .");
  servo1.attach(SERVO_PIN_1); Serial.print(".");
  servo2.attach(SERVO_PIN_2); Serial.println(".");
}

const int min = 0, max = 255;
int  cur = 0, factor = 1, wait = 10;

void loop() {
  // put your main code here, to run repeatedly:
  if(cur <= min){ // change to positive direction
    cur = 0; factor *= -1;
    Serial.println("Start positive direction");
  }else if( cur >= 255){ // change to negative direction
    cur = 255; factor *= -1;
    Serial.println("Start negative direction");
  } 

  Serial.print(".");
  servo1.write(cur);
  servo2.write(cur);
  
  cur += factor;
  delay(wait);
}