From 1dc8b9c0a9a9e594cb6cdc46982a155006b7db20 Mon Sep 17 00:00:00 2001 From: Pedro Weinzettel Date: Mon, 26 Jun 2017 11:38:51 -0300 Subject: [PATCH 1/4] Stepper.h - Add the ability to stop "steps" routine In one of my projects, I needed to stop the "steps" routine with an interruption. I just put and bool flag to keep it looping. Maybe someone else will find it interesting --- src/Stepper.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Stepper.h b/src/Stepper.h index 2e68979..c0e3cb9 100644 --- a/src/Stepper.h +++ b/src/Stepper.h @@ -96,6 +96,9 @@ class Stepper { // mover method: void step(int number_of_steps); + //stop rutine + void stop(void); + int version(void); private: From 6683cc9511efed8617cd9a4af41625956a1c9b18 Mon Sep 17 00:00:00 2001 From: Pedro Weinzettel Date: Mon, 26 Jun 2017 11:39:17 -0300 Subject: [PATCH 2/4] Stepper.cpp - Add the ability to stop "steps" routine In one of my projects, I needed to stop the "steps" routine with an interruption. I just put and bool flag to keep it looping. Maybe someone else will find it interesting --- src/Stepper.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Stepper.cpp b/src/Stepper.cpp index 1f76295..e390028 100644 --- a/src/Stepper.cpp +++ b/src/Stepper.cpp @@ -72,7 +72,7 @@ * * The circuits can be found at * - * http://www.arduino.cc/en/Tutorial/Stepper + * http://www.arduino.cc/en/Reference/Stepper */ #include "Arduino.h" @@ -177,6 +177,14 @@ void Stepper::setSpeed(long whatSpeed) this->step_delay = 60L * 1000L * 1000L / this->number_of_steps / whatSpeed; } +/* + * Sets the speed in revs per minute + */ +void Stepper::stop(void) +{ + this->set_stop = true; +} + /* * Moves the motor steps_to_move steps. If the number is negative, * the motor moves in the reverse direction. @@ -191,7 +199,8 @@ void Stepper::step(int steps_to_move) // decrement the number of steps, moving one step each time: - while (steps_left > 0) + this->set_stop = false; + while (steps_left > 0 && set_stop == false) { unsigned long now = micros(); // move only if the appropriate delay has passed: From 587681ff480cdb7d9612c83fde75e36b8d71ddd5 Mon Sep 17 00:00:00 2001 From: Pedro Weinzettel Date: Mon, 26 Jun 2017 11:40:08 -0300 Subject: [PATCH 3/4] keywords.txt - Add the ability to stop "steps" routine In one of my projects, I needed to stop the "steps" routine with an interruption. I just put and bool flag to keep it looping. Maybe someone else will find it interesting --- keywords.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/keywords.txt b/keywords.txt index 5e58a66..6e32c04 100644 --- a/keywords.txt +++ b/keywords.txt @@ -14,6 +14,7 @@ Stepper KEYWORD1 Stepper step KEYWORD2 setSpeed KEYWORD2 +stop KEYWORD2 version KEYWORD2 ###################################### From 3742914a9c94d81a08130c485358bbbd94295ecc Mon Sep 17 00:00:00 2001 From: Pedro Weinzettel Date: Mon, 17 Jul 2017 17:53:18 -0300 Subject: [PATCH 4/4] Update Stepper.cpp --- src/Stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stepper.cpp b/src/Stepper.cpp index e390028..c3d29a2 100644 --- a/src/Stepper.cpp +++ b/src/Stepper.cpp @@ -72,7 +72,7 @@ * * The circuits can be found at * - * http://www.arduino.cc/en/Reference/Stepper + * http://www.arduino.cc/en/Tutorial/Stepper */ #include "Arduino.h"