I am using Accelstepper
library to control a unipolar stepper motor. In my project, I would like to run the stepper in full-step mode when I need speed and in half-step mode when I need precision. As you know, the full-step/half-step selection is done in the very beginning of the sketch...
I found a workaround by creating two instances of Accelstepper
for the same stepper. That is:
Accelstepper fast(FULL4WIRE, 2,3,4,5);
Accelstepper slow(HALF4WIRE, 2,3,4,5);
With this, when I call (skipping other details of the code) fast.run()
the motor moves fast (full-step) and when I call slow.run()
it moves slowly as it is in half step mode.
But;
When it comes to determine to current motor position, this workaround fails, since there are two different values returned by the two functions: fast.currentPosition()
and slow.currentPosition()
. So this workaroud becomes useless.
My first question is: is there a way in Accelstepper
to switch from full-step to half-step and vice versa in the execution(let say in the loop)? If so, the second question can be skipped.
The second: XX.currentPosition()
function returns the value of a variable, namely "_currentPos" which is calculated in Accelstepper.cpp
file. As I understand, there become, as many _currentPos
values as Accelstepper
instances. In my case, one for fast and another for slow, and somehow they are kept and calculated individually without any confusion. Is there a way to access (extern?) and set this variable from the sketch, by referencing the specific Accelstepper
instence? Briefly, is there a way to copy one motor position to another?
Many thanks.