project for nrf51822 qfab

Dependencies:   eddystone_URL mbed

Fork of eddystone_URL by vo dung

Committer:
jksoft
Date:
Wed Nov 12 02:40:34 2014 +0000
Revision:
0:76dfa9657d9d
????????

Who changed what in which revision?

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