Turning on led while servo is moving

Your for() loops are not the same. In the second one, you count down from 180 to 0. When that is done, pos will be -1 so the test if if(pos==180) will NEVER be true.

Much easier to

  1. turn on LED
  2. execute for() loop from 0..180
  3. turn off first LED, turn on second LED
  4. execute for() loop from 180..0

No additional if() statements required.

As for the 4 hour delay, look at the Blink Without Delay example in the IDE (File->examples->02.Digital->Blink WIthout Delay) to learn how to track elapsed time without blocking other code from running.

1 Like