Skip to content

Stepper: avoid division by zero #4318

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

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 14 additions & 3 deletions libraries/Stepper/src/Stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2)
this->step_number = 0; // which step the motor is on
this->direction = 0; // motor direction
this->last_step_time = 0; // time stamp in us of the last step taken
this->number_of_steps = number_of_steps; // total number of steps for this motor
if (number_of_steps)
this->number_of_steps = number_of_steps; // total number of steps for this motor
else
this->number_of_steps = 1;

// Arduino pins for the motor control connection:
this->motor_pin_1 = motor_pin_1;
Expand Down Expand Up @@ -117,7 +120,10 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
this->step_number = 0; // which step the motor is on
this->direction = 0; // motor direction
this->last_step_time = 0; // time stamp in us of the last step taken
this->number_of_steps = number_of_steps; // total number of steps for this motor
if (number_of_steps)
this->number_of_steps = number_of_steps; // total number of steps for this motor
else
this->number_of_steps = 1;

// Arduino pins for the motor control connection:
this->motor_pin_1 = motor_pin_1;
Expand Down Expand Up @@ -149,7 +155,10 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
this->step_number = 0; // which step the motor is on
this->direction = 0; // motor direction
this->last_step_time = 0; // time stamp in us of the last step taken
this->number_of_steps = number_of_steps; // total number of steps for this motor
if (number_of_steps)
this->number_of_steps = number_of_steps; // total number of steps for this motor
else
this->number_of_steps = 1;

// Arduino pins for the motor control connection:
this->motor_pin_1 = motor_pin_1;
Expand All @@ -174,6 +183,8 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
*/
void Stepper::setSpeed(long whatSpeed)
{
if (whatSpeed == 0)
whatSpeed = 1;
this->step_delay = 60L * 1000L * 1000L / this->number_of_steps / whatSpeed;
}

Expand Down