Adafruit Motor Shield V2 Arduino Library
Public Member Functions | Friends | List of all members
Adafruit_MotorShield Class Reference

#include <Adafruit_MotorShield.h>

Public Member Functions

 Adafruit_MotorShield (uint8_t addr=0x60)
 Create the Motor Shield object at an I2C address, default is 0x60. More...
 
bool begin (uint16_t freq=1600, TwoWire *theWire=&Wire)
 Initialize the I2C hardware and PWM driver, then turn off all pins. More...
 
Adafruit_DCMotorgetMotor (uint8_t n)
 Mini factory that will return a pointer to an already-allocated Adafruit_DCMotor object. Initializes the DC motor and turns off all pins. More...
 
Adafruit_StepperMotorgetStepper (uint16_t steps, uint8_t n)
 Mini factory that will return a pointer to an already-allocated Adafruit_StepperMotor object with a given 'steps per rotation. Then initializes the stepper motor and turns off all pins. More...
 
void setPWM (uint8_t pin, uint16_t val)
 Helper that sets the PWM output on a pin and manages 'all on or off'. More...
 
void setPin (uint8_t pin, boolean val)
 Helper that sets the PWM output on a pin as if it were a GPIO. More...
 

Friends

class Adafruit_DCMotor
 Let DCMotors control the Shield.
 

Detailed Description

Object that controls and keeps state for the whole motor shield. Use it to create DC and Stepper motor objects!

Constructor & Destructor Documentation

◆ Adafruit_MotorShield()

Adafruit_MotorShield::Adafruit_MotorShield ( uint8_t  addr = 0x60)

Create the Motor Shield object at an I2C address, default is 0x60.

Parameters
addrOptional I2C address if you've changed it

Member Function Documentation

◆ begin()

bool Adafruit_MotorShield::begin ( uint16_t  freq = 1600,
TwoWire *  theWire = &Wire 
)

Initialize the I2C hardware and PWM driver, then turn off all pins.

Parameters
freqThe PWM frequency for the driver, used for speed control and microstepping. By default we use 1600 Hz which is a little audible but efficient.
theWireA pointer to an optional I2C interface. If not provided, we use Wire or Wire1 (on Due)
Returns
true if successful, false otherwise

◆ getMotor()

Adafruit_DCMotor * Adafruit_MotorShield::getMotor ( uint8_t  num)

Mini factory that will return a pointer to an already-allocated Adafruit_DCMotor object. Initializes the DC motor and turns off all pins.

Parameters
numThe DC motor port we want to use: 1 thru 4 are valid
Returns
NULL if something went wrong, or a pointer to a Adafruit_DCMotor

◆ getStepper()

Adafruit_StepperMotor * Adafruit_MotorShield::getStepper ( uint16_t  steps,
uint8_t  num 
)

Mini factory that will return a pointer to an already-allocated Adafruit_StepperMotor object with a given 'steps per rotation. Then initializes the stepper motor and turns off all pins.

Parameters
stepsHow many steps per revolution (used for RPM calculation)
numThe stepper motor port we want to use: only 1 or 2 are valid
Returns
NULL if something went wrong, or a pointer to a Adafruit_StepperMotor

◆ setPWM()

void Adafruit_MotorShield::setPWM ( uint8_t  pin,
uint16_t  value 
)

Helper that sets the PWM output on a pin and manages 'all on or off'.

Parameters
pinThe PWM output on the driver that we want to control (0-15)
valueThe 12-bit PWM value we want to set (0-4095) - 4096 is a special 'all on' value

◆ setPin()

void Adafruit_MotorShield::setPin ( uint8_t  pin,
boolean  value 
)

Helper that sets the PWM output on a pin as if it were a GPIO.

Parameters
pinThe PWM output on the driver that we want to control (0-15)
valueHIGH or LOW depending on the value you want!

The documentation for this class was generated from the following files: