kazushiro tanimoto
/
sagawa_lpc1114
Sagawa Electronics,inc.
Fork of sagawa_lpc1114 by
TB6612FNG/TB6612.h@0:d90f3421aaef, 2016-11-26 (annotated)
- Committer:
- zero515
- Date:
- Sat Nov 26 18:33:38 2016 +0000
- Revision:
- 0:d90f3421aaef
- Child:
- 1:dbde3f68f80d
sagawa mbed4adrobo sample program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zero515 | 0:d90f3421aaef | 1 | /* mbed TB6612FNG Library |
zero515 | 0:d90f3421aaef | 2 | * |
zero515 | 0:d90f3421aaef | 3 | * TB6612.h |
zero515 | 0:d90f3421aaef | 4 | * |
zero515 | 0:d90f3421aaef | 5 | * Copyright (c) 2010-2013 jksoft |
zero515 | 0:d90f3421aaef | 6 | * |
zero515 | 0:d90f3421aaef | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
zero515 | 0:d90f3421aaef | 8 | * of this software and associated documentation files (the "Software"), to deal |
zero515 | 0:d90f3421aaef | 9 | * in the Software without restriction, including without limitation the rights |
zero515 | 0:d90f3421aaef | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
zero515 | 0:d90f3421aaef | 11 | * copies of the Software, and to permit persons to whom the Software is |
zero515 | 0:d90f3421aaef | 12 | * furnished to do so, subject to the following conditions: |
zero515 | 0:d90f3421aaef | 13 | * |
zero515 | 0:d90f3421aaef | 14 | * The above copyright notice and this permission notice shall be included in |
zero515 | 0:d90f3421aaef | 15 | * all copies or substantial portions of the Software. |
zero515 | 0:d90f3421aaef | 16 | * |
zero515 | 0:d90f3421aaef | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
zero515 | 0:d90f3421aaef | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
zero515 | 0:d90f3421aaef | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
zero515 | 0:d90f3421aaef | 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
zero515 | 0:d90f3421aaef | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
zero515 | 0:d90f3421aaef | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
zero515 | 0:d90f3421aaef | 23 | * THE SOFTWARE. |
zero515 | 0:d90f3421aaef | 24 | */ |
zero515 | 0:d90f3421aaef | 25 | |
zero515 | 0:d90f3421aaef | 26 | #ifndef MBED_TB6612_H |
zero515 | 0:d90f3421aaef | 27 | #define MBED_TB6612_H |
zero515 | 0:d90f3421aaef | 28 | |
zero515 | 0:d90f3421aaef | 29 | #include "mbed.h" |
zero515 | 0:d90f3421aaef | 30 | #include "SoftPWM.h" |
zero515 | 0:d90f3421aaef | 31 | |
zero515 | 0:d90f3421aaef | 32 | /** TB6612FNG Library |
zero515 | 0:d90f3421aaef | 33 | * |
zero515 | 0:d90f3421aaef | 34 | * Example: |
zero515 | 0:d90f3421aaef | 35 | * @code |
zero515 | 0:d90f3421aaef | 36 | * // Drive the Motor |
zero515 | 0:d90f3421aaef | 37 | |
zero515 | 0:d90f3421aaef | 38 | #include "mbed.h" |
zero515 | 0:d90f3421aaef | 39 | #include "TB6612.h" |
zero515 | 0:d90f3421aaef | 40 | |
zero515 | 0:d90f3421aaef | 41 | TB6612 motor(p21,p5,p6); // PWMA,AIN1,AIN2 |
zero515 | 0:d90f3421aaef | 42 | |
zero515 | 0:d90f3421aaef | 43 | int main() { |
zero515 | 0:d90f3421aaef | 44 | |
zero515 | 0:d90f3421aaef | 45 | motor = 0.0; // Motor stopped. |
zero515 | 0:d90f3421aaef | 46 | |
zero515 | 0:d90f3421aaef | 47 | while(1) |
zero515 | 0:d90f3421aaef | 48 | { |
zero515 | 0:d90f3421aaef | 49 | motor = 0.5; // Motor forward. |
zero515 | 0:d90f3421aaef | 50 | wait(2.0); |
zero515 | 0:d90f3421aaef | 51 | motor = -0.5; // Motor reversal. |
zero515 | 0:d90f3421aaef | 52 | wait(2.0); |
zero515 | 0:d90f3421aaef | 53 | } |
zero515 | 0:d90f3421aaef | 54 | } |
zero515 | 0:d90f3421aaef | 55 | |
zero515 | 0:d90f3421aaef | 56 | * @endcode |
zero515 | 0:d90f3421aaef | 57 | */ |
zero515 | 0:d90f3421aaef | 58 | |
zero515 | 0:d90f3421aaef | 59 | class TB6612 { |
zero515 | 0:d90f3421aaef | 60 | // Public functions |
zero515 | 0:d90f3421aaef | 61 | public: |
zero515 | 0:d90f3421aaef | 62 | /** Create a TB6612 connected to the specified pins. |
zero515 | 0:d90f3421aaef | 63 | * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed.(PwmOutに対応したポートを指定します。) |
zero515 | 0:d90f3421aaef | 64 | * @param fwd A DigitalOut, set high when the motor should go forward.(DigitalOutに対応したポートを指定します。) |
zero515 | 0:d90f3421aaef | 65 | * @param rev A DigitalOut, set high when the motor should go backwards.(DigitalOutに対応したポートを指定します。) |
zero515 | 0:d90f3421aaef | 66 | */ |
zero515 | 0:d90f3421aaef | 67 | TB6612(PinName pwm, PinName fwd, PinName rev); |
zero515 | 0:d90f3421aaef | 68 | /** Directly control the speed and direction of the motor |
zero515 | 0:d90f3421aaef | 69 | * |
zero515 | 0:d90f3421aaef | 70 | * @param speed A normalised number -1.0 - 1.0 represents the full range. |
zero515 | 0:d90f3421aaef | 71 | * @return return the stopped state or direction of rotation. |
zero515 | 0:d90f3421aaef | 72 | */ |
zero515 | 0:d90f3421aaef | 73 | float speed(float speed); |
zero515 | 0:d90f3421aaef | 74 | /** A operator shorthand for speed() |
zero515 | 0:d90f3421aaef | 75 | * |
zero515 | 0:d90f3421aaef | 76 | */ |
zero515 | 0:d90f3421aaef | 77 | void operator= ( float value ) |
zero515 | 0:d90f3421aaef | 78 | { |
zero515 | 0:d90f3421aaef | 79 | speed(value); |
zero515 | 0:d90f3421aaef | 80 | } |
zero515 | 0:d90f3421aaef | 81 | operator int() |
zero515 | 0:d90f3421aaef | 82 | { |
zero515 | 0:d90f3421aaef | 83 | return(stat); |
zero515 | 0:d90f3421aaef | 84 | } |
zero515 | 0:d90f3421aaef | 85 | |
zero515 | 0:d90f3421aaef | 86 | protected: |
zero515 | 0:d90f3421aaef | 87 | SoftPWM _pwm; |
zero515 | 0:d90f3421aaef | 88 | DigitalOut _fwd; |
zero515 | 0:d90f3421aaef | 89 | DigitalOut _rev; |
zero515 | 0:d90f3421aaef | 90 | int stat; |
zero515 | 0:d90f3421aaef | 91 | }; |
zero515 | 0:d90f3421aaef | 92 | |
zero515 | 0:d90f3421aaef | 93 | #endif |