Rather than having the motors run on delay times, I would like them to run until the condition has been met and not increment to the next loop until that occurs. How do I accomplish this? Thanks.
What happens when it runs is that both motors try to run at the same time. The conditions work like a charm for each motor individually when the others are commented out.
if (Base < 370)
{
Base = analogRead(0); // read the input pin 0
Serial.println(" < 370 detected at base. Rotating clockwise ");
Serial.print("Base = ");
Serial.println(Base); // debug value
motor4.setSpeed(255);
motor4.run(FORWARD);
delay(500);
motor4.run(RELEASE);
}
else if (Base > 380) {
Base = analogRead(0); // read the input pin 0
Serial.println(" > 380 detected at base. Rotating counter-clockwise ");
Serial.print("Base = ");
Serial.println(Base); // debug value
motor4.setSpeed(255);
motor4.run(BACKWARD);
delay(500);
motor4.run(RELEASE);
}
if (Elbow < 545)
{
Serial.println(" < 545 detected at elbow. Rotating away from user ");
Elbow = analogRead(2); // read the input pin 2
Serial.print("Elbow = ");
Serial.println(Elbow); // debug value
motor3.setSpeed(255);
motor3.run(BACKWARD);
delay(500);
motor3.run(RELEASE);
}
else if (Elbow > 550) {
Serial.println(" > 550 detected at elbow. Rotating towards user ");
Elbow = analogRead(2); // read the input pin 2
Serial.print("Elbow = ");
Serial.println(Elbow); // debug value
motor3.setSpeed(255);
motor3.run(FORWARD);
delay(500);
motor3.run(RELEASE);
}