Skip to content

Reduced an unnecessary member variable #6

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 1 commit 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
11 changes: 3 additions & 8 deletions src/Stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
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

Expand Down Expand Up @@ -115,7 +114,6 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
int motor_pin_3, int motor_pin_4)
{
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

Expand Down Expand Up @@ -147,7 +145,6 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
int motor_pin_5)
{
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

Expand Down Expand Up @@ -185,10 +182,8 @@ void Stepper::step(int steps_to_move)
{
int steps_left = abs(steps_to_move); // how many steps to take

// determine direction based on whether steps_to_mode is + or -:
if (steps_to_move > 0) { this->direction = 1; }
if (steps_to_move < 0) { this->direction = 0; }

// determine direction based on whether steps_to_move is + or -:
int direction = (steps_to_move > 0 ? 1 : 0);

// decrement the number of steps, moving one step each time:
while (steps_left > 0)
Expand All @@ -201,7 +196,7 @@ void Stepper::step(int steps_to_move)
this->last_step_time = now;
// increment or decrement the step number,
// depending on direction:
if (this->direction == 1)
if (direction == 1)
{
this->step_number++;
if (this->step_number == this->number_of_steps) {
Expand Down
3 changes: 1 addition & 2 deletions src/Stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ class Stepper {
void setSpeed(long whatSpeed);

// mover method:
void step(int number_of_steps);
void step(int steps_to_move);

int version(void);

private:
void stepMotor(int this_step);

int direction; // Direction of rotation
unsigned long step_delay; // delay between steps, in ms, based on speed
int number_of_steps; // total number of steps this motor can take
int pin_count; // how many pins are in use.
Expand Down