keisuke Yoshida
/
BLE_WallbotBLE_Challenge_byYUTAKA
under constructiong
Fork of BLE_WallbotBLE_Challenge by
TB6612FNG/TB6612.cpp@2:3c406d25860e, 2015-02-20 (annotated)
- Committer:
- jksoft
- Date:
- Fri Feb 20 00:07:48 2015 +0000
- Revision:
- 2:3c406d25860e
- Parent:
- 0:76dfa9657d9d
- Child:
- 3:f707552ec50a
Wallbot BLE??????????
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:3c406d25860e | 46 | |
jksoft | 2:3c406d25860e | 47 | |
jksoft | 0:76dfa9657d9d | 48 | if( speed > 0.0 ) |
jksoft | 0:76dfa9657d9d | 49 | { |
jksoft | 2:3c406d25860e | 50 | if( speed > 0.7) speed = 0.7; |
jksoft | 0:76dfa9657d9d | 51 | _pwm = speed; |
jksoft | 0:76dfa9657d9d | 52 | _fwd = 1; |
jksoft | 0:76dfa9657d9d | 53 | _rev = 0; |
jksoft | 0:76dfa9657d9d | 54 | stat = 1; |
jksoft | 0:76dfa9657d9d | 55 | } |
jksoft | 0:76dfa9657d9d | 56 | else if( speed < 0.0 ) |
jksoft | 0:76dfa9657d9d | 57 | { |
jksoft | 2:3c406d25860e | 58 | if( speed < -0.7) speed = -0.7; |
jksoft | 0:76dfa9657d9d | 59 | _pwm = -speed; |
jksoft | 0:76dfa9657d9d | 60 | _fwd = 0; |
jksoft | 0:76dfa9657d9d | 61 | _rev = 1; |
jksoft | 0:76dfa9657d9d | 62 | stat = -1; |
jksoft | 0:76dfa9657d9d | 63 | } |
jksoft | 0:76dfa9657d9d | 64 | else |
jksoft | 0:76dfa9657d9d | 65 | { |
jksoft | 0:76dfa9657d9d | 66 | _fwd = 1; |
jksoft | 0:76dfa9657d9d | 67 | _rev = 1; |
jksoft | 0:76dfa9657d9d | 68 | stat = 0; |
jksoft | 0:76dfa9657d9d | 69 | } |
jksoft | 0:76dfa9657d9d | 70 | return speed==0 ? 0 : speed > 0 ? 1 : -1; |
jksoft | 0:76dfa9657d9d | 71 | } |