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