Skip to content

Support generic drivers for Stepper library #4257

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 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Revert implementation of motor delay in method step
Motor delay must support multitasking. See:
https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
  • Loading branch information
skniazev committed Dec 19, 2015
commit 5b947dcc35c65ed2653dc4122fcd3700b6dd2b78
8 changes: 7 additions & 1 deletion libraries/Stepper/src/Stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ void Stepper::step(int steps_to_move)
// decrement the number of steps, moving one step each time:
while (steps_left > 0)
{
delayMicroseconds(this->step_delay); // move only if the appropriate delay has passed
unsigned long now = micros();
// move only if the appropriate delay has passed:
if (now - this->last_step_time >= this->step_delay)
{
// get the timeStamp of when you stepped:
this->last_step_time = now;
// increment or decrement the step number,
// depending on direction:
if (steps_to_move >= 0)
Expand All @@ -174,6 +179,7 @@ void Stepper::step(int steps_to_move)
stepMotor(this->step_number % phase_count);
// decrement the steps left:
steps_left--;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions libraries/Stepper/src/Stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class Stepper {

// motor pin numbers:
unsigned char motor_pin[5]; // Maximum 5 control signals
unsigned long last_step_time; // time stamp in us of when the last step was taken
};

#endif
Expand Down