Adafruit Motor Shield V2 Arduino Library
Adafruit_MotorShield.h
1 /******************************************************************
2  This is the library for the Adafruit Motor Shield V2 for Arduino.
3  It supports DC motors & Stepper motors with microstepping as well
4  as stacking-support. It is *not* compatible with the V1 library!
5 
6  It will only work with https://www.adafruit.com/products/1483
7 
8  Adafruit invests time and resources providing this open
9  source code, please support Adafruit and open-source hardware
10  by purchasing products from Adafruit!
11 
12  Written by Limor Fried/Ladyada for Adafruit Industries.
13  BSD license, check license.txt for more information.
14  All text above must be included in any redistribution.
15  ******************************************************************/
16 
17 #ifndef _Adafruit_MotorShield_h_
18 #define _Adafruit_MotorShield_h_
19 
20 #include <inttypes.h>
21 
22 #include "utility/Adafruit_MS_PWMServoDriver.h"
23 
24 // #define MOTORDEBUG
25 
26 #define MICROSTEPS 16 // 8 or 16
27 
28 #define MOTOR1_A 2
29 #define MOTOR1_B 3
30 #define MOTOR2_A 1
31 #define MOTOR2_B 4
32 #define MOTOR4_A 0
33 #define MOTOR4_B 6
34 #define MOTOR3_A 5
35 #define MOTOR3_B 7
36 
37 #define FORWARD 1
38 #define BACKWARD 2
39 #define BRAKE 3
40 #define RELEASE 4
41 
42 #define SINGLE 1
43 #define DOUBLE 2
44 #define INTERLEAVE 3
45 #define MICROSTEP 4
46 
48 
51  public:
52  Adafruit_DCMotor(void);
53  friend class Adafruit_MotorShield;
54  void run(uint8_t);
55  void setSpeed(uint8_t);
56  void setSpeedFine(uint16_t speed);
57  void fullOn();
58  void fullOff();
59 
60  private:
61  uint8_t PWMpin, IN1pin, IN2pin;
63  uint8_t motornum;
64 };
65 
68  public:
70  void setSpeed(uint16_t);
71 
72  void step(uint16_t steps, uint8_t dir, uint8_t style = SINGLE);
73  uint8_t onestep(uint8_t dir, uint8_t style);
74  void release(void);
75 
76  friend class Adafruit_MotorShield;
77 
78  private:
79  uint32_t usperstep;
80 
81  uint8_t PWMApin, AIN1pin, AIN2pin;
82  uint8_t PWMBpin, BIN1pin, BIN2pin;
83  uint16_t revsteps; // # steps per revolution
84  uint8_t currentstep;
86  uint8_t steppernum;
87 };
88 
92  public:
93  Adafruit_MotorShield(uint8_t addr = 0x60);
94 
95  bool begin(uint16_t freq = 1600, TwoWire* theWire = &Wire);
96  Adafruit_DCMotor* getMotor(uint8_t n);
97  Adafruit_StepperMotor* getStepper(uint16_t steps, uint8_t n);
98 
99  friend class Adafruit_DCMotor;
100 
101  void setPWM(uint8_t pin, uint16_t val);
102  void setPin(uint8_t pin, boolean val);
103 
104  private:
105  uint8_t _addr;
106  uint16_t _freq;
107  Adafruit_DCMotor dcmotors[4];
108  Adafruit_StepperMotor steppers[2];
109  Adafruit_MS_PWMServoDriver _pwm;
110 };
111 
112 #endif
void fullOn()
Set DC motor to full on.
Definition: Adafruit_MotorShield.cpp:273
Definition: Adafruit_MotorShield.h:50
void run(uint8_t)
Control the DC Motor direction and action.
Definition: Adafruit_MotorShield.cpp:231
Definition: Adafruit_MotorShield.h:91
void setSpeed(uint8_t)
Control the DC Motor speed/throttle.
Definition: Adafruit_MotorShield.cpp:254
void setSpeedFine(uint16_t speed)
Control the DC Motor speed/throttle with 12 bit resolution.
Definition: Adafruit_MotorShield.cpp:264
Adafruit_DCMotor(void)
Create a DCMotor object, un-initialized! You should never call this, instead have the Adafruit_MotorS...
Definition: Adafruit_MotorShield.cpp:219
Definition: Adafruit_MotorShield.h:67
friend class Adafruit_MotorShield
Let MotorShield create DCMotors.
Definition: Adafruit_MotorShield.h:53
void fullOff()
Set DC motor to full off.
Definition: Adafruit_MotorShield.cpp:282