Datasheet
class Adafruit_DCMotor
The Adafruit_DCMotor class represents a DC motor attached to the shield. You must declare an Adafruit_DCMotor for
each motor in your system.
Adafruit_DCMotor(void);
The constructor takes no arguments. The motor object is typically initialized by assigning a motor object retrieved from
the shield class as below:
void run(uint8_t);
The run() function controls the motor state. The parameter can have one of 3 values:
FORWARD - Rotate in a forward direction
BACKWARD - Rotate in the reverse direction
RELEASE - Stop rotation
Note that the "FORWARD" and "BACKWARD" directions are arbitrary. If they do not match the actual direction of your
vehicle or robot, simple swap the motor leads.
Also note that "RELEASE" simply cuts power to the motor. It does not apply any braking.
void setSpeed(uint8_t);
The setSpeed() function controls the power level delivered to the motor. The speed parameter is a value between 0
and 255.
Note that setSpeed just controls the power delivered to the motor. The actual speed of the motor will depend on
several factors, including: The motor, the power supply and the load.
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);
© Adafruit Industries https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino Page 36 of 43