Reputation: 1
void setLimits() {
delay(1000);
stepperOne.setMaxSpeed(25);
stepperOne.setAcceleration(10);
stepperTwo.setMaxSpeed(25);
stepperTwo.setAcceleration(10);
stepperThree.setMaxSpeed(25);
stepperThree.setAcceleration(10);
homeTWO();
homeTHREE();
homeONE();
delay(5000);
}
// THE HOMING EACH MOTOR SUBROUTINES****
void homeTWO() {
while (switch_status == LOW && homing_counter == 0) {
stepperTwo.move(-1); // movesteps
stepperTwo.runToPosition(); // run until desired position is reached
limitSwitch.loop();
switch_status = limitSwitch.getState();
}
if (switch_status == HIGH && homing_counter == 0) {
stepperTwo.move(11); // movesteps
stepperTwo.runToPosition(); // run until desired position is reached
delay(10);
homing_counter = 1;
switch_status = (LOW);
}
}
void homeTHREE() {
while (switch_status == LOW && homing_counter == 1) {
stepperThree.move(-1); // movesteps
stepperThree.runToPosition(); // run until desired position is reached
limitSwitch.loop();
switch_status = limitSwitch.getState();
}
if (switch_status == HIGH && homing_counter == 1) {
stepperThree.move(11); // movesteps
stepperThree.runToPosition(); // run until desired position is reached
delay(10);
homing_counter = 2;
switch_status = (LOW);
}
}
void homeONE() {
while (switch_status == LOW && homing_counter == 2) {
stepperOne.move(-1); // movesteps
stepperOne.runToPosition(); // run until desired position is reached
limitSwitch.loop();
switch_status = limitSwitch.getState();
}
if (switch_status == HIGH && homing_counter == 2) {
stepperOne.move(11); // movesteps
stepperOne.runToPosition(); // run until desired position is reached
delay(10);
homing_counter = 1;
switch_status = (LOW);
}
}
I'm running code to move the stepper one step at a time until the switch reads high. I have three motors and identical code for all three. I have currently wired only one limit switch to function all three sections of code as well as initiate some other portions of the program. The limit switch is wired correctly and produces the results I want but only sometimes. It is debounced and pulled up via ezButton library in Arduino.
When I run the code, the first motor will behave as expected, it will take one step at a time until I click the button, then it will take the multiple steps on a "HIGH" read from the button and move onto the next motor homing.
The next motor to home will take one step in the homing direction and then jump right to the next cycle instead of clicking along in the while loop. The next motor behaves the same.
I've tried setting my limit switch integer back to low in between functions and all other iterations of solutions I could think of. Why does it work for one and then runs all the code for the other two but doesn't get stuck in the while loop taking single steps until the button is triggered?
Upvotes: 0
Views: 15