Skip to content

Commit 5b947dc

Browse files
committed
Revert implementation of motor delay in method step
Motor delay must support multitasking. See: https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
1 parent 388460f commit 5b947dc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

libraries/Stepper/src/Stepper.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ void Stepper::step(int steps_to_move)
153153
// decrement the number of steps, moving one step each time:
154154
while (steps_left > 0)
155155
{
156-
delayMicroseconds(this->step_delay); // move only if the appropriate delay has passed
156+
unsigned long now = micros();
157+
// move only if the appropriate delay has passed:
158+
if (now - this->last_step_time >= this->step_delay)
159+
{
160+
// get the timeStamp of when you stepped:
161+
this->last_step_time = now;
157162
// increment or decrement the step number,
158163
// depending on direction:
159164
if (steps_to_move >= 0)
@@ -174,6 +179,7 @@ void Stepper::step(int steps_to_move)
174179
stepMotor(this->step_number % phase_count);
175180
// decrement the steps left:
176181
steps_left--;
182+
}
177183
}
178184
}
179185

libraries/Stepper/src/Stepper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class Stepper {
156156

157157
// motor pin numbers:
158158
unsigned char motor_pin[5]; // Maximum 5 control signals
159+
unsigned long last_step_time; // time stamp in us of when the last step was taken
159160
};
160161

161162
#endif

0 commit comments

Comments
 (0)