library for the motor driver
Dependents: 4180_final_project
Fork of libTCS34725 by
TB6612FNG.h@7:e1be74ebe7be, 2017-04-18 (annotated)
- Committer:
- mwilkens241
- Date:
- Tue Apr 18 19:53:13 2017 +0000
- Revision:
- 7:e1be74ebe7be
- Parent:
- 6:560b232837cf
fixed standby error
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 | 7:e1be74ebe7be | 59 | /** Stops the motor from moving |
mwilkens241 | 7:e1be74ebe7be | 60 | */ |
mwilkens241 | 7:e1be74ebe7be | 61 | void stop(); |
mwilkens241 | 7:e1be74ebe7be | 62 | |
mwilkens241 | 5:822a7407ccb3 | 63 | /** Disables the motor, puts it into standby |
mwilkens241 | 3:afb107db7994 | 64 | */ |
mwilkens241 | 7:e1be74ebe7be | 65 | void standby(); |
mwilkens241 | 3:afb107db7994 | 66 | |
mwilkens241 | 5:822a7407ccb3 | 67 | /** Sets the motor to move forward at a given speed (as a percent [0,1]) |
mwilkens241 | 5:822a7407ccb3 | 68 | * @param speed Speed of the motor as a percent [0,1] |
mwilkens241 | 3:afb107db7994 | 69 | */ |
mwilkens241 | 5:822a7407ccb3 | 70 | void fwd(float speed); |
mwilkens241 | 5:822a7407ccb3 | 71 | |
mwilkens241 | 5:822a7407ccb3 | 72 | /** Sets the motor to move backward at a given speed (as a percent [0,1]) |
mwilkens241 | 5:822a7407ccb3 | 73 | * @param speed Speed of the motor as a percent [0,1] |
mwilkens241 | 5:822a7407ccb3 | 74 | */ |
mwilkens241 | 5:822a7407ccb3 | 75 | void rev(float speed); |
mwilkens241 | 5:822a7407ccb3 | 76 | |
mwilkens241 | 3:afb107db7994 | 77 | }; |
mwilkens241 | 2:cc2c0831a763 | 78 | |
mwilkens241 | 3:afb107db7994 | 79 | #endif |