Skip to content

Commit a9278c5

Browse files
committed
Optimization of method initMotor()
Optimization of method initMotor() by refusing of the case switch
1 parent a6e3b3c commit a9278c5

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

libraries/Stepper/src/Stepper.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,24 +206,12 @@ void Stepper::initMotor(int number_of_steps, unsigned char motor_pin_1, unsign
206206
this->phase_count = phase_count;
207207
// phasesMatrix is used by the stepMotor() method:
208208
this->phasesMatrix = phasesMatrix;
209+
this->motor_pin[0] = motor_pin_1;
210+
this->motor_pin[1] = motor_pin_2;
211+
this->motor_pin[2] = motor_pin_3;
212+
this->motor_pin[3] = motor_pin_4;
213+
this->motor_pin[4] = motor_pin_5;
209214
for (unsigned char i = 0; i < this->pin_count; i++){
210-
switch (i) {
211-
case 0:
212-
this->motor_pin[i] = motor_pin_1; // Arduino pin 1 for the motor control connection
213-
break;
214-
case 1:
215-
this->motor_pin[i] = motor_pin_2; // Arduino pin 2 for the motor control connection
216-
break;
217-
case 2:
218-
this->motor_pin[i] = motor_pin_3; // Arduino pin 3 for the motor control connection
219-
break;
220-
case 3:
221-
this->motor_pin[i] = motor_pin_4; // Arduino pin 4 for the motor control connection
222-
break;
223-
case 4:
224-
this->motor_pin[i] = motor_pin_5; // Arduino pin 5 for the motor control connection
225-
break;
226-
}
227215
pinMode(this->motor_pin[i], OUTPUT); // setup the pins on the microcontroller
228216
}
229217
}

0 commit comments

Comments
 (0)