I am trying to control the position of multiple stepper motors, and then reset its position by rotating counter clockwise,until it hits the limit switch, and loop through these functions. I tested the autohome and runmotors functions separately and they work as intended (The runmotors function takes in parameters from the serial to determine its end position).
When I run the current code, it skips the runmotors function and performs the autohome function, but once it hits the limit switch it does not stop, even though it works fine when I remove the runmotors function. How would I get it to runmotors, wait until that function has finished, and then perform the autohome function?
void autohome(){
if(digitalRead(limX) == HIGH){
motorX.setSpeed(25);
motorX.runSpeed();
}
else if(digitalRead(limX) == LOW){
motorX.stop();
}
if(digitalRead(limY) == HIGH){
motorY.setSpeed(25);
motorY.runSpeed();
}
else if(digitalRead(limY) == LOW){
motorY.stop();
}
if(digitalRead(limZ) == HIGH){
motorZ.setSpeed(25);
motorZ.runSpeed();
}
else if(digitalRead(limZ) == LOW){
motorZ.stop();
}
}
void runmotors(){
motorX.moveTo(theta1 / -1.8);
// motorY.moveTo(theta2 / -1.8);
// motorZ.moveTo(theta3 / -1.8);
//
motorX.run();
// motorY.run();
// motorZ.run();
}
void loop() {
runmotors();
autohome();
}