Datasheet
Create the DC motor object
Request the DC motor from the Adafruit_MotorShield:
with getMotor(port#). Port# is which port it is connected to. If you're using M1 its 1, M2 use 2, M3 use 3 and M4 use 4
Connect to the Controller
In your setup() function, call begin() on the Adafruit_MotorShield object:
Set default speed
Set the speed of the motor using setSpeed(
speed
) where the
speed
ranges from 0 (stopped) to 255 (full speed). You
can set the speed whenever you want.
Run the motor
To run the motor, call run(
direction
) where
direction
is FORWARD, BACKWARD or RELEASE. Of course, the Arduino
doesn't actually know if the motor is 'forward' or 'backward', so if you want to change which way it thinks is forward,
simply swap the two wires from the motor to the shield.
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
AFMS.begin();
myMotor->setSpeed(150);
myMotor->run(FORWARD);
© Adafruit Industries https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino Page 31 of 43