#include <Servo.h>

long s,state = 0;

Servo tServo;

void setup() {
  Serial.begin(9600);
tServo.attach(6);
}

void loop() {

 
 while(s < 180 && state == 0){
 tServo.write(s);
 s=s+20;
 if ( s == 180){
state = 1;
 }
 Serial.print(" 1: ");
 Serial.println(s);
 delay(200);
 }
 
 while(s > 0 && state == 1){
 tServo.write(s);
 s=s-20;
 if ( s == 0){
 state = 0;
 }Serial.print(" 2: ");
 Serial.println(s);
 
 delay(200);
 }

}
