Skip to main content
2 of 4
Fixed the indent and made loop start at 150 like OP has.

If you want to change the servo every second, try to use a conditional expression in the timing structure. If you want to use more parallel structure with multiple intervals use different counters (example see: here).

Here is an example of the every second version:

#include <Servo.h> Servo myservo; unsigned long previousMillis = 0; const long interval = 1000; int angle = 150; void setup() { myservo.attach(9); myservo.write(angle); } void loop() { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; switch (angle) { case 150: case 65: myservo.write(15); break; case 15: myservo.write(35); break; case 35: myservo.write(65); break; } } } 
user3704293
  • 471
  • 7
  • 20