library for the motor driver
Dependents: 4180_final_project
Fork of libTCS34725 by
TB6612FNG.h@6:560b232837cf, 2017-03-31 (annotated)
- Committer:
- mwilkens241
- Date:
- Fri Mar 31 15:50:00 2017 +0000
- Revision:
- 6:560b232837cf
- Parent:
- 5:822a7407ccb3
- Child:
- 7:e1be74ebe7be
added encoder support then deleted it
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mwilkens241 | 5:822a7407ccb3 | 1 | // TB6612FNG Motor Driver |
mwilkens241 | 5:822a7407ccb3 | 2 | #ifndef MBED_TB6612FNG_H |
mwilkens241 | 5:822a7407ccb3 | 3 | #define MBED_TB6612FNG_H |
mwilkens241 | 3:afb107db7994 | 4 | |
mwilkens241 | 1:06c9bbbdb8b0 | 5 | #include "mbed.h" |
mwilkens241 | 0:4796574af790 | 6 | |
mwilkens241 | 5:822a7407ccb3 | 7 | /** TB6612FNG control class. |
mwilkens241 | 3:afb107db7994 | 8 | * |
mwilkens241 | 3:afb107db7994 | 9 | * Example: |
mwilkens241 | 3:afb107db7994 | 10 | * @code |
mwilkens241 | 4:cc00e3842f1b | 11 | * //Perform readings on two i2c devices with the same address |
mwilkens241 | 5:822a7407ccb3 | 12 | * #include "TB6612FNG.h" |
mwilkens241 | 3:afb107db7994 | 13 | * #include "mbed.h" |
mwilkens241 | 3:afb107db7994 | 14 | * |
mwilkens241 | 3:afb107db7994 | 15 | * |
mwilkens241 | 3:afb107db7994 | 16 | * int main() { |
mwilkens241 | 3:afb107db7994 | 17 | * |
mwilkens241 | 4:cc00e3842f1b | 18 | * while(1) { |
mwilkens241 | 3:afb107db7994 | 19 | * } |
mwilkens241 | 3:afb107db7994 | 20 | * } |
mwilkens241 | 3:afb107db7994 | 21 | * @endcode |
mwilkens241 | 3:afb107db7994 | 22 | */ |
mwilkens241 | 0:4796574af790 | 23 | |
mwilkens241 | 5:822a7407ccb3 | 24 | class TB6612FNG { |
mwilkens241 | 3:afb107db7994 | 25 | private: |
mwilkens241 | 5:822a7407ccb3 | 26 | bool on; |
mwilkens241 | 5:822a7407ccb3 | 27 | |
mwilkens241 | 5:822a7407ccb3 | 28 | DigitalOut *dir1; |
mwilkens241 | 5:822a7407ccb3 | 29 | DigitalOut *dir2; |
mwilkens241 | 5:822a7407ccb3 | 30 | PwmOut *pwm; |
mwilkens241 | 5:822a7407ccb3 | 31 | DigitalOut *stby; |
mwilkens241 | 5:822a7407ccb3 | 32 | |
mwilkens241 | 3:afb107db7994 | 33 | public: |
mwilkens241 | 5:822a7407ccb3 | 34 | /** Initialize object with default pins */ |
mwilkens241 | 5:822a7407ccb3 | 35 | TB6612FNG(); |
mwilkens241 | 3:afb107db7994 | 36 | |
mwilkens241 | 6:560b232837cf | 37 | /** Initialize object with specific motor pins |
mwilkens241 | 3:afb107db7994 | 38 | * |
mwilkens241 | 5:822a7407ccb3 | 39 | * @param idir1 Direction pin (IN1) |
mwilkens241 | 5:822a7407ccb3 | 40 | * @param idir2 Second direction pin (IN2) |
mwilkens241 | 5:822a7407ccb3 | 41 | * @param ipwm Motor PWM pin (PWM) |
mwilkens241 | 5:822a7407ccb3 | 42 | * @param istby SCL pin |
mwilkens241 | 3:afb107db7994 | 43 | */ |
mwilkens241 | 5:822a7407ccb3 | 44 | TB6612FNG(PinName idir1, PinName idir2, PinName ipwm, PinName istby); |
mwilkens241 | 3:afb107db7994 | 45 | |
mwilkens241 | 5:822a7407ccb3 | 46 | /** Change the pins the motor was initialized with |
mwilkens241 | 3:afb107db7994 | 47 | * |
mwilkens241 | 5:822a7407ccb3 | 48 | * @param idir1 Direction pin (IN1) |
mwilkens241 | 5:822a7407ccb3 | 49 | * @param idir2 Second direction pin (IN2) |
mwilkens241 | 5:822a7407ccb3 | 50 | * @param ipwm Motor PWM pin (PWM) |
mwilkens241 | 5:822a7407ccb3 | 51 | * @param istby SCL pin |
mwilkens241 | 5:822a7407ccb3 | 52 | */ |
mwilkens241 | 5:822a7407ccb3 | 53 | void config(PinName idir1, PinName idir2, PinName ipwm, PinName istby); |
mwilkens241 | 5:822a7407ccb3 | 54 | |
mwilkens241 | 5:822a7407ccb3 | 55 | /** Enables the motor |
mwilkens241 | 5:822a7407ccb3 | 56 | */ |
mwilkens241 | 5:822a7407ccb3 | 57 | void start(); |
mwilkens241 | 5:822a7407ccb3 | 58 | |
mwilkens241 | 5:822a7407ccb3 | 59 | /** Disables the motor, puts it into standby |
mwilkens241 | 3:afb107db7994 | 60 | */ |
mwilkens241 | 5:822a7407ccb3 | 61 | void stop(); |
mwilkens241 | 3:afb107db7994 | 62 | |
mwilkens241 | 5:822a7407ccb3 | 63 | /** Sets the motor to move forward at a given speed (as a percent [0,1]) |
mwilkens241 | 5:822a7407ccb3 | 64 | * @param speed Speed of the motor as a percent [0,1] |
mwilkens241 | 3:afb107db7994 | 65 | */ |
mwilkens241 | 5:822a7407ccb3 | 66 | void fwd(float speed); |
mwilkens241 | 5:822a7407ccb3 | 67 | |
mwilkens241 | 5:822a7407ccb3 | 68 | /** Sets the motor to move backward at a given speed (as a percent [0,1]) |
mwilkens241 | 5:822a7407ccb3 | 69 | * @param speed Speed of the motor as a percent [0,1] |
mwilkens241 | 5:822a7407ccb3 | 70 | */ |
mwilkens241 | 5:822a7407ccb3 | 71 | void rev(float speed); |
mwilkens241 | 5:822a7407ccb3 | 72 | |
mwilkens241 | 3:afb107db7994 | 73 | }; |
mwilkens241 | 2:cc2c0831a763 | 74 | |
mwilkens241 | 3:afb107db7994 | 75 | #endif |