ilikecats567 / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Small change to Stepper library that allows for interrupting step() method #945

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What change would like to see?

I added a few lines to the Stepper library so I could interrupt the step() 
method (which is normally blocking) from within an interrupt.

Why?

To be able to do something like myStepper.step(1000) and have it stop when an 
interrupt (from a photo interruptor pin change, for example) fires.

for example:

  // attachInterrupt(0, sensorChange, FALLING);

  void sensorChange() {
     myStepper.stop();
  }

Would this cause any incompatibilities with previous versions?  If so, how
can these be mitigated?

No, no incompatibilities.

Rob Duarte - rob@rahji.com

Original issue reported on code.google.com by rah...@gmail.com on 3 Jun 2012 at 4:53

Attachments:

GoogleCodeExporter commented 9 years ago
This does seem useful but I'm reluctant to add a stop() function that only 
works / makes sense if called from an interrupt because I'm afraid it might 
confuse people that don't understand how it / they work.  You can get the same 
effect from only calling step() with 1 or -1, right (and putting the flag in 
your sketch's code)?  That seems like a better approach, unless this use 
(stopping the stepper from an interrupt) is common.

Original comment by dmel...@gmail.com on 17 Jul 2012 at 3:06

GoogleCodeExporter commented 9 years ago
I understand not wanting to add this because of potential confusion, but just 
so you know.. the alternative method you mention is not the same as using 
interrupts with stop(). Calling step(1) and checking a flag only works if your 
sketch does nothing else inside the loop().  For example, calling step(1) 
followed by some other work on the part of your program causes a series of 
"single" steps with some delay between them.  The idea with the interrupt 
solution is that you can set the motor running at a predetermined speed and 
have it move at that speed until the interrupt fires, regardless of whatever 
other work you're doing in the sketch.  (The purpose of interrupts, in general, 
I suppose).  

Original comment by rah...@gmail.com on 22 Jul 2012 at 6:23