@@ -94,7 +94,6 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2)
94
94
0 , 0 , 0 , (unsigned char *)phasesMatrix2, 2 , 4 );
95
95
}
96
96
97
-
98
97
/*
99
98
* constructor for four-pin version
100
99
* Sets which wires should control the motor.
@@ -155,55 +154,48 @@ void Stepper::step(int steps_to_move)
155
154
while (steps_left > 0 )
156
155
{
157
156
delayMicroseconds (this ->step_delay ); // move only if the appropriate delay has passed
158
- // unsigned long now = micros();
159
- // // move only if the appropriate delay has passed:
160
- // if (now - this->last_step_time >= this->step_delay)
161
- // {
162
- // // get the timeStamp of when you stepped:
163
- // this->last_step_time = now;
164
157
// increment or decrement the step number,
165
158
// depending on direction:
166
159
if (steps_to_move >= 0 )
167
160
{
168
161
this ->step_number ++;
169
- if (this ->step_number = = this ->number_of_steps ) {
162
+ if (this ->step_number > = this ->number_of_steps ) {
170
163
this ->step_number = 0 ;
171
164
}
172
165
}
173
166
else
174
167
{
175
- if (this ->step_number = = 0 ) {
168
+ if (this ->step_number < = 0 ) {
176
169
this ->step_number = this ->number_of_steps ;
177
170
}
178
171
this ->step_number --;
179
172
}
180
- // decrement the steps left:
181
- steps_left--;
182
173
// step the motor to step number 0, 1, ..., {3 or 9}
183
174
stepMotor (this ->step_number % phase_count);
184
- // }
175
+ // decrement the steps left:
176
+ steps_left--;
185
177
}
186
178
}
187
179
188
180
/*
189
181
* Moves the motor forward or backwards.
190
182
*/
191
- void Stepper::stepMotor (int thisPhase)
183
+ void Stepper::stepMotor (unsigned char thisPhase)
192
184
{
193
185
unsigned char phase = pgm_read_byte_near (phasesMatrix + thisPhase);
194
186
unsigned char running_one = 0b10000000 ;
195
- for (int i = 0 ; i < pin_count; i++, running_one >>= 1 ){
187
+ for (unsigned char i = 0 ; i < pin_count; i++, running_one >>= 1 ){
196
188
digitalWrite (motor_pin[i], (phase & running_one));
197
189
}
198
190
}
199
191
200
192
/*
201
193
* Initialize the motor
202
194
*/
203
- void Stepper::initMotor (int number_of_steps, int motor_pin_1, int motor_pin_2,
204
- int motor_pin_3, int motor_pin_4,
205
- int motor_pin_5, unsigned char *phasesMatrix,
206
- int pin_count, int phase_count)
195
+ void Stepper::initMotor (int number_of_steps, unsigned char motor_pin_1, unsigned char motor_pin_2,
196
+ unsigned char motor_pin_3, unsigned char motor_pin_4,
197
+ unsigned char motor_pin_5, unsigned char *phasesMatrix,
198
+ unsigned char pin_count, unsigned char phase_count)
207
199
{
208
200
this ->step_number = 0 ; // which step the motor is on
209
201
this ->number_of_steps = number_of_steps; // total number of steps for this motor
@@ -214,7 +206,7 @@ void Stepper::initMotor(int number_of_steps, int motor_pin_1, int motor_pin_2,
214
206
this ->phase_count = phase_count;
215
207
// phasesMatrix is used by the stepMotor() method:
216
208
this ->phasesMatrix = phasesMatrix;
217
- for (int i = 0 ; i < this ->pin_count ; i++){
209
+ for (unsigned char i = 0 ; i < this ->pin_count ; i++){
218
210
switch (i) {
219
211
case 0 :
220
212
this ->motor_pin [i] = motor_pin_1; // Arduino pin 1 for the motor control connection
0 commit comments