Turning on led while servo is moving

The first for() loop looks correct, the second one does not need to digitalWrite every time through the loop.

digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
for (pos = 180; pos >= 0; pos -= 1) { /* goes from 180 degrees to 0 degrees */
    myservo.write(pos);           
    delay(15);    
}
digitalWrite(LED2, LOW);

Now, go learn the Blink Without Delay example

1 Like