Skip to content

Add ability to stop "step" routine #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Stepper KEYWORD1 Stepper

step KEYWORD2
setSpeed KEYWORD2
stop KEYWORD2
version KEYWORD2

######################################
Expand Down
11 changes: 10 additions & 1 deletion src/Stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/Stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class Stepper {
// mover method:
void step(int number_of_steps);

//stop rutine
void stop(void);

int version(void);

private:
Expand Down