#include <Servo.h>

Servo myservo;

int pos = 0;

void setup() {
  myservo.attach(9); //Servo Pin D9
  pinMode(8, OUTPUT); //LED-A Pin D8
  pinMode(10, OUTPUT); //LED-B Pin D10
  myservo.write(90); //Initial Servo Horn Position 90°
  delay(4000); //Initial Delay 4000mS (optional)

}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) {
    myservo.write(pos);
    delay(20);
  }
  digitalWrite(8, HIGH);
  delay(20);
  digitalWrite(10, LOW);


  for (pos = 180; pos >= 0; pos -= 1) {
    myservo.write(pos);
    delay(20);
  }
  digitalWrite(10, HIGH);
  delay(20);
  digitalWrite(8, LOW);

}