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:
<!-- language: c -->
#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:
angle = 15;
myservo.write(angle);
break;
case 15:
angle = 35;
myservo.write(angle);
break;
case 35:
angle = 65;
myservo.write(angle);
break;
}
}
}
**EDIT:** Add variable assignment `angle` in conditional expression.
[here]:https://stackoverflow.com/questions/32037217/how-can-i-replace-delay-by-millis/32043899#32043899