Skip to content

Commit d35936c

Browse files
authored
A new function to idle the motor after stepping
A new function that allow setting the idle option to power down all the motor coils after stepping, in order to reduce power and heat. That also allows manual rotation of the motor.
1 parent 4c9d6cd commit d35936c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Stepper.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2)
8888
this->direction = 0; // motor direction
8989
this->last_step_time = 0; // timestamp in us of the last step taken
9090
this->number_of_steps = number_of_steps; // total number of steps for this motor
91+
this->idle = false; // Power down all coils after done stepping
9192

9293
// Arduino pins for the motor control connection:
9394
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,
118119
this->direction = 0; // motor direction
119120
this->last_step_time = 0; // timestamp in us of the last step taken
120121
this->number_of_steps = number_of_steps; // total number of steps for this motor
122+
this->idle = false; // Power down all coils after done stepping
121123

122124
// Arduino pins for the motor control connection:
123125
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,
150152
this->direction = 0; // motor direction
151153
this->last_step_time = 0; // timestamp in us of the last step taken
152154
this->number_of_steps = number_of_steps; // total number of steps for this motor
155+
this->idle = false; // Power down all coils after done stepping
153156

154157
// Arduino pins for the motor control connection:
155158
this->motor_pin_1 = motor_pin_1;
@@ -226,6 +229,21 @@ void Stepper::step(int steps_to_move)
226229
yield();
227230
}
228231
}
232+
// If ideling is enabled then power down all coils
233+
if (this->idle == true)
234+
{
235+
digitalWrite(motor_pin_1, LOW);
236+
digitalWrite(motor_pin_2, LOW);
237+
if (this->pin_count == 4)
238+
{
239+
digitalWrite(motor_pin_1, LOW);
240+
digitalWrite(motor_pin_2, LOW);
241+
digitalWrite(motor_pin_3, LOW);
242+
digitalWrite(motor_pin_4, LOW);
243+
}
244+
if (this->pin_count == 5)
245+
digitalWrite(motor_pin_5, LOW);
246+
}
229247
}
230248

231249
/*
@@ -358,6 +376,15 @@ void Stepper::stepMotor(int thisStep)
358376
}
359377
}
360378

379+
/*
380+
* Allow powering down all coils after stepping,
381+
* to reduce heat, power and allow manuall rotation.
382+
*/
383+
void Stepper::idelAfterStep(bool idle)
384+
{
385+
this->idle = idle;
386+
}
387+
361388
/*
362389
version() returns the version of the library:
363390
*/

0 commit comments

Comments
 (0)