a

Committer:
jksoft
Date:
Fri Aug 29 04:40:40 2014 +0000
Revision:
4:95d5e9ee8c15
Parent:
2:ad4e7374e5c1
Child:
5:096c2484805d
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 2:ad4e7374e5c1 1 /* wallbot mini Library
jksoft 2:ad4e7374e5c1 2 *
jksoft 2:ad4e7374e5c1 3 * wallbotmini.cpp
jksoft 2:ad4e7374e5c1 4 *
jksoft 2:ad4e7374e5c1 5 * Copyright (c) 2010-2013 jksoft
jksoft 0:810f315ba3dc 6 *
jksoft 2:ad4e7374e5c1 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
jksoft 2:ad4e7374e5c1 8 * of this software and associated documentation files (the "Software"), to deal
jksoft 2:ad4e7374e5c1 9 * in the Software without restriction, including without limitation the rights
jksoft 2:ad4e7374e5c1 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jksoft 2:ad4e7374e5c1 11 * copies of the Software, and to permit persons to whom the Software is
jksoft 2:ad4e7374e5c1 12 * furnished to do so, subject to the following conditions:
jksoft 0:810f315ba3dc 13 *
jksoft 2:ad4e7374e5c1 14 * The above copyright notice and this permission notice shall be included in
jksoft 2:ad4e7374e5c1 15 * all copies or substantial portions of the Software.
jksoft 2:ad4e7374e5c1 16 *
jksoft 2:ad4e7374e5c1 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jksoft 2:ad4e7374e5c1 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jksoft 2:ad4e7374e5c1 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jksoft 2:ad4e7374e5c1 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jksoft 2:ad4e7374e5c1 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jksoft 2:ad4e7374e5c1 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jksoft 2:ad4e7374e5c1 23 * THE SOFTWARE.
jksoft 0:810f315ba3dc 24 */
jksoft 0:810f315ba3dc 25
jksoft 0:810f315ba3dc 26
jksoft 0:810f315ba3dc 27 #include "TB6612.h"
jksoft 0:810f315ba3dc 28
jksoft 0:810f315ba3dc 29 // TB6612 Class Constructor
jksoft 0:810f315ba3dc 30 TB6612::TB6612(PinName pwm, PinName fwd, PinName rev):
jksoft 0:810f315ba3dc 31 _pwm(pwm), _fwd(fwd), _rev(rev) {
jksoft 0:810f315ba3dc 32
jksoft 0:810f315ba3dc 33 _fwd = 0;
jksoft 0:810f315ba3dc 34 _rev = 0;
jksoft 0:810f315ba3dc 35 _pwm = 0.0;
jksoft 4:95d5e9ee8c15 36 stat = 0;
jksoft 0:810f315ba3dc 37 _pwm.period(0.001);
jksoft 0:810f315ba3dc 38
jksoft 0:810f315ba3dc 39 }
jksoft 0:810f315ba3dc 40
jksoft 0:810f315ba3dc 41 // Speed Control
jksoft 0:810f315ba3dc 42 // arg
jksoft 0:810f315ba3dc 43 // float speed -1.0 - 0.0 - 1.0
jksoft 2:ad4e7374e5c1 44 float TB6612::speed(float speed) {
jksoft 0:810f315ba3dc 45
jksoft 0:810f315ba3dc 46 if( speed > 0.0 )
jksoft 0:810f315ba3dc 47 {
jksoft 0:810f315ba3dc 48 _pwm = speed;
jksoft 0:810f315ba3dc 49 _fwd = 1;
jksoft 0:810f315ba3dc 50 _rev = 0;
jksoft 4:95d5e9ee8c15 51 stat = 1;
jksoft 0:810f315ba3dc 52 }
jksoft 0:810f315ba3dc 53 else if( speed < 0.0 )
jksoft 0:810f315ba3dc 54 {
jksoft 0:810f315ba3dc 55 _pwm = -speed;
jksoft 0:810f315ba3dc 56 _fwd = 0;
jksoft 0:810f315ba3dc 57 _rev = 1;
jksoft 4:95d5e9ee8c15 58 stat = -1;
jksoft 0:810f315ba3dc 59 }
jksoft 0:810f315ba3dc 60 else
jksoft 0:810f315ba3dc 61 {
jksoft 0:810f315ba3dc 62 _fwd = 1;
jksoft 0:810f315ba3dc 63 _rev = 1;
jksoft 4:95d5e9ee8c15 64 stat = 0;
jksoft 0:810f315ba3dc 65 }
jksoft 2:ad4e7374e5c1 66 return speed==0 ? 0 : speed > 0 ? 1 : -1;
jksoft 2:ad4e7374e5c1 67 }