diff --git a/src/Stepper.cpp b/src/Stepper.cpp index 148de03..98fbf00 100644 --- a/src/Stepper.cpp +++ b/src/Stepper.cpp @@ -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; @@ -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; @@ -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; @@ -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); + } } /* @@ -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: */ diff --git a/src/Stepper.h b/src/Stepper.h index b5578b4..0ea8aa8 100644 --- a/src/Stepper.h +++ b/src/Stepper.h @@ -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); @@ -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;