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 "utility/Adafruit_MS_PWMServoDriver.h"
21 #include <inttypes.h>
22 
23 //#define MOTORDEBUG
24 
25 #define MICROSTEPS 16 // 8 or 16
26 
27 #define MOTOR1_A 2
28 #define MOTOR1_B 3
29 #define MOTOR2_A 1
30 #define MOTOR2_B 4
31 #define MOTOR4_A 0
32 #define MOTOR4_B 6
33 #define MOTOR3_A 5
34 #define MOTOR3_B 7
35 
36 #define FORWARD 1
37 #define BACKWARD 2
38 #define BRAKE 3
39 #define RELEASE 4
40 
41 #define SINGLE 1
42 #define DOUBLE 2
43 #define INTERLEAVE 3
44 #define MICROSTEP 4
45 
47 
50 public:
51  Adafruit_DCMotor(void);
52  friend class Adafruit_MotorShield;
53  void run(uint8_t);
54  void setSpeed(uint8_t);
55  void setSpeedFine(uint16_t speed);
56  void fullOn();
57  void fullOff();
58 
59 private:
60  uint8_t PWMpin, IN1pin, IN2pin;
62  uint8_t motornum;
63 };
64 
67 public:
69  void setSpeed(uint16_t);
70 
71  void step(uint16_t steps, uint8_t dir, uint8_t style = SINGLE);
72  uint8_t onestep(uint8_t dir, uint8_t style);
73  void release(void);
74 
75  friend class Adafruit_MotorShield;
76 
77 private:
78  uint32_t usperstep;
79 
80  uint8_t PWMApin, AIN1pin, AIN2pin;
81  uint8_t PWMBpin, BIN1pin, BIN2pin;
82  uint16_t revsteps; // # steps per revolution
83  uint8_t currentstep;
85  uint8_t steppernum;
86 };
87 
91 public:
92  Adafruit_MotorShield(uint8_t addr = 0x60);
93 
94  bool begin(uint16_t freq = 1600, TwoWire *theWire = &Wire);
95  Adafruit_DCMotor *getMotor(uint8_t n);
96  Adafruit_StepperMotor *getStepper(uint16_t steps, uint8_t n);
97 
98  friend class Adafruit_DCMotor;
99 
100  void setPWM(uint8_t pin, uint16_t val);
101  void setPin(uint8_t pin, boolean val);
102 
103 private:
104  uint8_t _addr;
105  uint16_t _freq;
106  Adafruit_DCMotor dcmotors[4];
107  Adafruit_StepperMotor steppers[2];
108  Adafruit_MS_PWMServoDriver _pwm;
109 };
110 
111 #endif
void fullOn()
Set DC motor to full on.
Definition: Adafruit_MotorShield.cpp:269
Definition: Adafruit_MotorShield.h:49
void run(uint8_t)
Control the DC Motor direction and action.
Definition: Adafruit_MotorShield.cpp:227
Definition: Adafruit_MotorShield.h:90
void setSpeed(uint8_t)
Control the DC Motor speed/throttle.
Definition: Adafruit_MotorShield.cpp:250
void setSpeedFine(uint16_t speed)
Control the DC Motor speed/throttle with 12 bit resolution.
Definition: Adafruit_MotorShield.cpp:260
Adafruit_DCMotor(void)
Create a DCMotor object, un-initialized! You should never call this, instead have the Adafruit_MotorS...
Definition: Adafruit_MotorShield.cpp:215
Definition: Adafruit_MotorShield.h:66
friend class Adafruit_MotorShield
Let MotorShield create DCMotors.
Definition: Adafruit_MotorShield.h:52
void fullOff()
Set DC motor to full off.
Definition: Adafruit_MotorShield.cpp:276