OK, I'm trying to replace those delays with millis but I am lost. I hope someone can help set me in the right direction (some sample code would be really helpful).
Here's my somewhat revised code:
#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 currentMillis = 0; // stores the value of millis() in each iteration of loop()
unsigned long previousLeftMillis = 0;
unsigned long previousRightMillis = 0;
unsigned long previousLeftServoMillis = 0; // the time when the servo was last moved
const long leftServoInterval = 2000; //activate left servo every 2 seconds
const long rightServoInterval = 3000; //activate right servo every 3 seconds
unsigned long leftServoTimer;
unsigned long rightServoTimer;
void setup() {
}
void loop() {
currentMillis = millis();
leftServoMove();
//rightServoMove();
}
void leftServoMove() {
leftServo.attach(9);
if (currentMillis - previousLeftServoMillis >= leftServoInterval) {
previousLeftServoMillis = leftServoInterval;
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();
}