The syntax seems off from the examples we have; I've got two motor shields, and would like to be able to address each motor set by changing a single variable; currently, I've got:
Code: Select all
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x60);
// Second motor shield
Adafruit_MotorShield AFMS_2 = Adafruit_MotorShield(0x61);
// Set motor names
Adafruit_DCMotor *myMotor_1 = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor_2 = AFMS.getMotor(2);
Adafruit_DCMotor *myMotor_3 = AFMS.getMotor(3);
Adafruit_DCMotor *myMotor_4 = AFMS.getMotor(4);
Adafruit_DCMotor *myMotor_5 = AFMS_2.getMotor(1);
So, the alternate would seem to be something along the lines of (dimension to 6, since we'll not use the 0th element - trying to write
this for someone who might get confused...
):
(However, the MotorArray[1] = ... statements are rejected)...
Code: Select all
// alternate
Adafruit_DCMotor* MotorArray[6];
Adafruit_DCMotor *Motor1 = AFMS.getMotor(1);
Adafruit_DCMotor *Motor2 = AFMS.getMotor(2);
Adafruit_DCMotor *Motor3 = AFMS.getMotor(3);
Adafruit_DCMotor *Motor4 = AFMS.getMotor(4);
Adafruit_DCMotor *Motor5 = AFMS_2.getMotor(1);
MotorArray[1] = &Motor1;
MotorArray[2] = &Motor2;
MotorArray[3] = &Motor3;
MotorArray[4] = &Motor4;
MotorArray[5] = &Motor5;
So, two questions:
1) How to fix the definitions above
2) How do we change statements (like the following) to reflect this array-based system?
myMotor_1->setSpeed(MotorSpeed);
myMotor_1->run(FORWARD);