admin管理员组文章数量:1287514
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?
本文标签: stepperConfusing behavior while using arduino and limit switchesStack Overflow
版权声明:本文标题:stepper - Confusing behavior while using arduino and limit switches - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741308750a2371525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论