The start function not working when called from an if sentence, but works when called directly. Why, and is there a workaround?
void loop(){
if(x==0){//remove these 2 lines and it works
start();
}//remove these 2 lines and it works
}
}
void start(){
myStepper.setMaxSpeed(200);
myStepper.setAcceleration(50);
myStepper.moveTo(140);
myStepper.run();
}
at a higher frequency than the next step must be created.
This is the price for non-blocking step-pulse creation
loop must run very fast.
The alternative is to use a blocking function for the step-pulse-creation
But as the name "blocking" says no other code can be executed as long as the step-pulse-creation is active = steppermotor is rotating.
The only way to have both non-blocking step-pulse-creation and "slow" running loop()
is to use a timerinterrupt for step-pulse-creation.
The MobaTools-Library does exactly this. Non-blocking step-pulse-creation "in the backround" through a timer-interrupt.
"set and forget" step-pulse-creation.
The function-calls in the MobaTools-library have different names than in the accellstepper-library. Once you have learned them it is easy to use.
So you have to decide between investing time for
re-writing your code beeing non-blocking again and having a fast running loop
or
investing time to learn the function-calls of the MobaTools-Library and never again think about
"will my loop() still be fast enough to call often enough myStepper.run(); ?????
I'm pretty sure it can be solved in an easy way.
To make a suggestion you would have to post a description of your project and the wanted functionality.
I'm serious: The description should have only normal words. No coding-terms
After reading Stefan L38´s comments and studying AccelStepper on other forums I found an easy solution: In this case using a blocking command is no problem.
Info on AccelSteppers commands is scarce, but in this case: