Skip to content
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 @@ -15,6 +15,7 @@ Stepper KEYWORD1 Stepper
step KEYWORD2
setSpeed KEYWORD2
version KEYWORD2
idelAfterStep KEYWORD2

######################################
# Instances (KEYWORD2)
Expand Down
27 changes: 27 additions & 0 deletions src/Stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2)
this->direction = 0; // motor direction
this->last_step_time = 0; // timestamp in us of the last step taken
this->number_of_steps = number_of_steps; // total number of steps for this motor
this->idle = false; // Power down all coils after done stepping

// Arduino pins for the motor control connection:
this->motor_pin_1 = motor_pin_1;
Expand Down Expand Up @@ -118,6 +119,7 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
this->direction = 0; // motor direction
this->last_step_time = 0; // timestamp in us of the last step taken
this->number_of_steps = number_of_steps; // total number of steps for this motor
this->idle = false; // Power down all coils after done stepping

// Arduino pins for the motor control connection:
this->motor_pin_1 = motor_pin_1;
Expand Down Expand Up @@ -150,6 +152,7 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
this->direction = 0; // motor direction
this->last_step_time = 0; // timestamp in us of the last step taken
this->number_of_steps = number_of_steps; // total number of steps for this motor
this->idle = false; // Power down all coils after done stepping

// Arduino pins for the motor control connection:
this->motor_pin_1 = motor_pin_1;
Expand Down Expand Up @@ -226,6 +229,21 @@ void Stepper::step(int steps_to_move)
yield();
}
}
// If ideling is enabled then power down all coils
if (this->idle == true)
{
digitalWrite(motor_pin_1, LOW);
digitalWrite(motor_pin_2, LOW);
if (this->pin_count == 4)
{
digitalWrite(motor_pin_1, LOW);
digitalWrite(motor_pin_2, LOW);
digitalWrite(motor_pin_3, LOW);
digitalWrite(motor_pin_4, LOW);
}
if (this->pin_count == 5)
digitalWrite(motor_pin_5, LOW);
}
}

/*
Expand Down Expand Up @@ -358,6 +376,15 @@ void Stepper::stepMotor(int thisStep)
}
}

/*
* Allow powering down all coils after stepping,
* to reduce heat, power and allow manual rotation.
*/
void Stepper::idelAfterStep(bool idle)
{
this->idle = idle;
}

/*
version() returns the version of the library:
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class Stepper {

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

// Power down all coils after stepping, to reduce heat, power and allow manual rotation.
void idelAfterStep(bool idle);

int version(void);

Expand All @@ -106,6 +109,7 @@ class Stepper {
int number_of_steps; // total number of steps this motor can take
int pin_count; // how many pins are in use.
int step_number; // which step the motor is on
bool idle; // Power down all coils after done stepping

// motor pin numbers:
int motor_pin_1;
Expand Down