Btw, code in post #20 has to be changed to make proper direction changes in all step phases.
Current code has a step sequence discontinuity / hick-up when changing direction in lines 36 and 43.
After issuing a stop, there is also a small issue: if stopping in an 'instable' step phase - where two magnetic fields 'fight' for the rotor and move the rotor between the fighting poles - it may come to rest in either pole position - back or forward after digitalWrite of 0b000 / taking the power off. To compensate for that when continuing, power with the same last step phase has to be applied before moving on... - of course for the proper amount of time. Implementation depends on whether the setInterval(...) invokes the function the first time at beginning or end of the first interval, which I do not know.
Simplest resolution is to remove the stop() in the direction change, change the stop, and - most important - change the sequence in the backward steps sequence and adjust the step adjustment in direction change.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Btw, code in post #20 has to be changed to make proper direction changes in all step phases.
Current code has a step sequence discontinuity / hick-up when changing direction in lines 36 and 43.
After issuing a stop, there is also a small issue: if stopping in an 'instable' step phase - where two magnetic fields 'fight' for the rotor and move the rotor between the fighting poles - it may come to rest in either pole position - back or forward after digitalWrite of 0b000 / taking the power off. To compensate for that when continuing, power with the same last step phase has to be applied before moving on... - of course for the proper amount of time. Implementation depends on whether the setInterval(...) invokes the function the first time at beginning or end of the first interval, which I do not know.
Simplest resolution is to remove the stop() in the direction change, change the stop, and - most important - change the sequence in the backward steps sequence and adjust the step adjustment in direction change.
This are the 4 changed lines:
16.
var stBW = [0b1001,0b0001,0b0011,0b0010,0b0110,0b0100,0b1100,0b1000];
36.
} else { if (stT) { st = Math.abs(st - 7); } if (!stI) { st--; } setI((stT = t),stFW," FW"); }
43.
} else { if (stT) { st = Math.abs(st - 7); } if (!stI) { st--; } setI(-(stT = t),stBW," BW"); }
49.
if (stI) { stI = clearInterval(stI); stI = null; }
Resulting code: