waspinator / AccelStepper

Fork of AccelStepper
http://www.airspayce.com/mikem/arduino/AccelStepper/
Other
149 stars 87 forks source link

Interruping blocking-mode functions (e.g., limit switch) #38

Open luriomer opened 5 months ago

luriomer commented 5 months ago

Hello,

In my application I'd like to incorporate limit switches that would stop the motor immediately when engaged (e.g., when reaching a hardstop). For non-blocking mode functions (i.e., constantly calling run() or runSpeed() inside a loop) it is pretty straight-forward by either interrupts or polling. No problem there.

I wonder if there is a way to do the same for blocking functions, such as runToPosition(). Even if I interrupt to set a flag or whatever, as soon as the ISR function returns (which will be very shortly, if it's just setting a flag) the motor will continue the movement (and if a hard stop was reached it will just slip and won't move). So basically what I am looking for is a way to use interrupts to conditionally break out runToPosition.

I would say this is a pretty basic feature that many other might need.

Thanks!