Trying to make servo-driven eyebrows on a face go up and down at different times together. I can only get them to go in sequence -- first the left one goes, then the right, then the left. I want them to go at the same time but with different timing.
I can get LEDs to work properly using millis but I can't get these darn servos to cooperate.
The 'Several Things at a Time' tutorial that gets recommended regularly has a servo, but only one and in a sweep motion. I can't make out how to apply that to this issue.
Any help would be appreciated
#include <Servo.h>
Servo leftServo;
Servo rightServo;
int leftServoUpPos = 130; //CCW
int leftServoDownPos = 90; //CW
int waitLeftServoUp = 555;
int waitLeftServoDown = 555;
int rightServoUpPos = 60; //CCW
int rightServoDownPos = 100; //CW
int waitRightServoUp = 555;
int waitRightServoDown = 555;
unsigned long previousLeftMillis = 0;
unsigned long previousRightMillis = 0;
const long leftInterval = 2000; //activate left servo every 2 seconds
const long rightInterval = 3000; //activate right servo every 3 seconds
unsigned long leftServoTimer;
unsigned long rightServoTimer;
void setup() {
}
void loop() {
unsigned long currentLeftMillis = millis();
if (currentLeftMillis - previousLeftMillis >= leftInterval) {
previousLeftMillis = currentLeftMillis;
leftServoMove();
}
unsigned long currentRightMillis = millis();
if (currentRightMillis - previousRightMillis >= rightInterval) {
previousRightMillis = currentRightMillis;
rightServoMove();
}
}
void leftServoMove() {
leftServo.attach(9);
leftServo.write(leftServoDownPos);
delay(waitLeftServoDown);
leftServo.write(leftServoUpPos);
delay(waitLeftServoUp);
leftServo.write(leftServoDownPos);
delay(waitLeftServoDown);
leftServoTimer = millis();
}
void rightServoMove() {
rightServo.attach(10);
rightServo.write(rightServoDownPos);
delay(waitRightServoDown);
rightServo.write(rightServoUpPos);
delay(waitRightServoUp);
rightServo.write(rightServoDownPos);
delay(waitRightServoDown);
rightServo.detach();
rightServoTimer = millis();
}