Adafruit_Motor_Shield_V2_Library icon indicating copy to clipboard operation
Adafruit_Motor_Shield_V2_Library copied to clipboard

Potential bug for method getMotor and getStepper of class Adafruit_MotorShield

Open flahaye opened this issue 11 years ago • 1 comments

In getMotor, to determine if the motor are init'd, you test the value of member motornum (line 72) with zero and assign num to motornum (line 74). In the case of the motor one, num are the value zero when motornum is assigned to num because of the decrement line 70. The first motor is always init'd. It's the same for getStepper. However, I haven't yet tested the code.

flahaye avatar Mar 07 '14 08:03 flahaye

Yes

basically

dcmotors[num].motornum

is not really needed. the code only needs to store a boolean to see if the dcmotor has been initialised already.

so the code should look like

if (!dcmotors[num].init) { // not init'd yet! dcmotors[num].init = true;

audetto avatar Aug 14 '15 20:08 audetto