I want my servo motors to move in the same motion and direction at the same time but with different start times. This is the data of how I want it to move.
This is the code I have as of now;
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
int pos = 180;
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 200; //the value is a number of milliseconds, ie 1 second
void setup() {
// put your setup code here, to run once:
int pos = 180;
servo1.attach(1);
servo2.attach(3);
servo3.attach(5);
servo4.attach(7);
servo5.attach(9);
servo1.write(pos);
servo2.write(pos);
servo3.write(pos);
servo4.write(pos);
servo5.write(pos);
startMillis = millis();
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long currentMillis = millis();
servo5.write(0);
for (pos = 180; pos >= 80; pos -= 1){
if (currentMillis - startMillis >= period)
{
servo2.write(pos);
}
servo1.write(pos);
delay(20);
}
for (pos = 80; pos <= 180; pos += 1){
servo1.write(pos);
delay(20);
}
}
