a
TB6612.h@5:096c2484805d, 2021-11-06 (annotated)
- Committer:
- miyajitakenari
- Date:
- Sat Nov 06 03:07:17 2021 +0000
- Revision:
- 5:096c2484805d
- Parent:
- 4:95d5e9ee8c15
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:810f315ba3dc | 1 | #ifndef MBED_TB6612_H |
jksoft | 0:810f315ba3dc | 2 | #define MBED_TB6612_H |
jksoft | 0:810f315ba3dc | 3 | |
jksoft | 0:810f315ba3dc | 4 | #include "mbed.h" |
jksoft | 0:810f315ba3dc | 5 | |
jksoft | 2:ad4e7374e5c1 | 6 | /** TB6612FNG Library |
jksoft | 2:ad4e7374e5c1 | 7 | * |
jksoft | 2:ad4e7374e5c1 | 8 | * Example: |
jksoft | 2:ad4e7374e5c1 | 9 | * @code |
jksoft | 2:ad4e7374e5c1 | 10 | * // Drive the Motor |
jksoft | 2:ad4e7374e5c1 | 11 | |
jksoft | 2:ad4e7374e5c1 | 12 | #include "mbed.h" |
jksoft | 2:ad4e7374e5c1 | 13 | #include "TB6612.h" |
jksoft | 2:ad4e7374e5c1 | 14 | |
jksoft | 2:ad4e7374e5c1 | 15 | TB6612 motor(p21,p5,p6); // PWMA,AIN1,AIN2 |
jksoft | 2:ad4e7374e5c1 | 16 | |
jksoft | 2:ad4e7374e5c1 | 17 | int main() { |
jksoft | 2:ad4e7374e5c1 | 18 | |
jksoft | 2:ad4e7374e5c1 | 19 | motor = 0.0; // Motor stopped. |
jksoft | 2:ad4e7374e5c1 | 20 | |
jksoft | 2:ad4e7374e5c1 | 21 | while(1) |
jksoft | 2:ad4e7374e5c1 | 22 | { |
jksoft | 2:ad4e7374e5c1 | 23 | motor = 0.5; // Motor forward. |
jksoft | 2:ad4e7374e5c1 | 24 | wait(2.0); |
jksoft | 2:ad4e7374e5c1 | 25 | motor = -0.5; // Motor reversal. |
jksoft | 2:ad4e7374e5c1 | 26 | wait(2.0); |
jksoft | 2:ad4e7374e5c1 | 27 | } |
jksoft | 2:ad4e7374e5c1 | 28 | } |
jksoft | 2:ad4e7374e5c1 | 29 | |
jksoft | 2:ad4e7374e5c1 | 30 | * @endcode |
jksoft | 2:ad4e7374e5c1 | 31 | */ |
jksoft | 2:ad4e7374e5c1 | 32 | |
jksoft | 0:810f315ba3dc | 33 | class TB6612 { |
jksoft | 2:ad4e7374e5c1 | 34 | // Public functions |
jksoft | 0:810f315ba3dc | 35 | public: |
jksoft | 2:ad4e7374e5c1 | 36 | /** Create a TB6612 connected to the specified pins. |
jksoft | 3:34ddc9038d9d | 37 | * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed.(PwmOutに対応したポートを指定します。) |
jksoft | 3:34ddc9038d9d | 38 | * @param fwd A DigitalOut, set high when the motor should go forward.(DigitalOutに対応したポートを指定します。) |
jksoft | 3:34ddc9038d9d | 39 | * @param rev A DigitalOut, set high when the motor should go backwards.(DigitalOutに対応したポートを指定します。) |
jksoft | 2:ad4e7374e5c1 | 40 | */ |
jksoft | 0:810f315ba3dc | 41 | TB6612(PinName pwm, PinName fwd, PinName rev); |
jksoft | 2:ad4e7374e5c1 | 42 | /** Directly control the speed and direction of the motor |
jksoft | 2:ad4e7374e5c1 | 43 | * |
jksoft | 2:ad4e7374e5c1 | 44 | * @param speed A normalised number -1.0 - 1.0 represents the full range. |
jksoft | 2:ad4e7374e5c1 | 45 | * @return return the stopped state or direction of rotation. |
jksoft | 2:ad4e7374e5c1 | 46 | */ |
miyajitakenari | 5:096c2484805d | 47 | float speed(double speed); |
jksoft | 2:ad4e7374e5c1 | 48 | /** A operator shorthand for speed() |
jksoft | 2:ad4e7374e5c1 | 49 | * |
jksoft | 2:ad4e7374e5c1 | 50 | */ |
jksoft | 0:810f315ba3dc | 51 | void operator= ( float value ) |
jksoft | 0:810f315ba3dc | 52 | { |
jksoft | 0:810f315ba3dc | 53 | speed(value); |
jksoft | 0:810f315ba3dc | 54 | } |
jksoft | 4:95d5e9ee8c15 | 55 | operator int() |
jksoft | 4:95d5e9ee8c15 | 56 | { |
jksoft | 4:95d5e9ee8c15 | 57 | return(stat); |
jksoft | 4:95d5e9ee8c15 | 58 | } |
jksoft | 0:810f315ba3dc | 59 | |
jksoft | 0:810f315ba3dc | 60 | protected: |
jksoft | 0:810f315ba3dc | 61 | PwmOut _pwm; |
jksoft | 0:810f315ba3dc | 62 | DigitalOut _fwd; |
jksoft | 0:810f315ba3dc | 63 | DigitalOut _rev; |
jksoft | 4:95d5e9ee8c15 | 64 | int stat; |
jksoft | 0:810f315ba3dc | 65 | }; |
jksoft | 0:810f315ba3dc | 66 | |
jksoft | 0:810f315ba3dc | 67 | #endif |