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
Child:
2:3c406d25860e
????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:76dfa9657d9d 1 /* wallbot mini Library
jksoft 0:76dfa9657d9d 2 *
jksoft 0:76dfa9657d9d 3 * wallbotmini.cpp
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
jksoft 0:76dfa9657d9d 27 #include "TB6612.h"
jksoft 0:76dfa9657d9d 28
jksoft 0:76dfa9657d9d 29 // TB6612 Class Constructor
jksoft 0:76dfa9657d9d 30 TB6612::TB6612(PinName pwm, PinName fwd, PinName rev):
jksoft 0:76dfa9657d9d 31 _pwm(pwm), _fwd(fwd), _rev(rev) {
jksoft 0:76dfa9657d9d 32
jksoft 0:76dfa9657d9d 33 _fwd = 0;
jksoft 0:76dfa9657d9d 34 _rev = 0;
jksoft 0:76dfa9657d9d 35 _pwm = 0.0;
jksoft 0:76dfa9657d9d 36 stat = 0;
jksoft 0:76dfa9657d9d 37 _pwm.period(0.001);
jksoft 0:76dfa9657d9d 38
jksoft 0:76dfa9657d9d 39 }
jksoft 0:76dfa9657d9d 40
jksoft 0:76dfa9657d9d 41 // Speed Control
jksoft 0:76dfa9657d9d 42 // arg
jksoft 0:76dfa9657d9d 43 // float speed -1.0 - 0.0 - 1.0
jksoft 0:76dfa9657d9d 44 float TB6612::speed(float speed) {
jksoft 0:76dfa9657d9d 45
jksoft 0:76dfa9657d9d 46 if( speed > 0.0 )
jksoft 0:76dfa9657d9d 47 {
jksoft 0:76dfa9657d9d 48 _pwm = speed;
jksoft 0:76dfa9657d9d 49 _fwd = 1;
jksoft 0:76dfa9657d9d 50 _rev = 0;
jksoft 0:76dfa9657d9d 51 stat = 1;
jksoft 0:76dfa9657d9d 52 }
jksoft 0:76dfa9657d9d 53 else if( speed < 0.0 )
jksoft 0:76dfa9657d9d 54 {
jksoft 0:76dfa9657d9d 55 _pwm = -speed;
jksoft 0:76dfa9657d9d 56 _fwd = 0;
jksoft 0:76dfa9657d9d 57 _rev = 1;
jksoft 0:76dfa9657d9d 58 stat = -1;
jksoft 0:76dfa9657d9d 59 }
jksoft 0:76dfa9657d9d 60 else
jksoft 0:76dfa9657d9d 61 {
jksoft 0:76dfa9657d9d 62 _fwd = 1;
jksoft 0:76dfa9657d9d 63 _rev = 1;
jksoft 0:76dfa9657d9d 64 stat = 0;
jksoft 0:76dfa9657d9d 65 }
jksoft 0:76dfa9657d9d 66 return speed==0 ? 0 : speed > 0 ? 1 : -1;
jksoft 0:76dfa9657d9d 67 }