Hello, I am new with Servo motors and when I was trying to make two of them move simultaneously, but to different positions with different speeds, only one of them would move at a time, even if I called the 2 functions one after the other. I thought it might be because I am using the Delay() function, but I am unsure if it is really because of this, and of how I could use delayMicroseconds() or Micros() instead. I would really appreciate it if someone knew what to do, thank you.
#include <Servo.h>
Servo servoMotor;
Servo servoMotor2;
int pos = 90;
int pos2 = 90;
int intensity;
int captor = A0;
void setup() {
Serial.begin(9600);
servoMotor.attach(7);
servoMotor2.attach(8);
}
void loop() {
intensity = analogRead(captor);
if (intensity>5) //
{ // Stuff with ligths here
}
else
{
moveMotor();
moveMotor2();
}
delay(100);
}
void moveMotor() {
for (pos = 90; pos <= 140; pos += 1) {
servoMotor.write(pos);
delay(15);
}
for (pos = 140; pos >= 90; pos -= 1) {
servoMotor.write(pos);
delay(15);
}
}
void moveMotor2() {
for (pos2 = 90; pos2 <= 95; pos2 += 1) {
servoMotor2.write(pos2);
delay(15);
}
for (pos2 = 95; pos2 >= 90; pos2 -= 1) {
servoMotor2.write(pos2);
delay(15);
}
for (pos2 = 90; pos2 >= 85; pos2 -= 1) {
servoMotor2.write(pos2);
delay(15);
}
for (pos2 = 85; pos2 <= 90; pos2 += 1) {
servoMotor2.write(pos2);
delay(15);
}
}