a
TB6612.cpp@1:051a7ecff13e, 2012-11-12 (annotated)
- Committer:
- jksoft
- Date:
- Mon Nov 12 16:39:11 2012 +0000
- Revision:
- 1:051a7ecff13e
- Parent:
- 0:810f315ba3dc
API??????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:810f315ba3dc | 1 | /** |
jksoft | 0:810f315ba3dc | 2 | * Motor Driver TB6612 Control Library |
jksoft | 0:810f315ba3dc | 3 | * |
jksoft | 0:810f315ba3dc | 4 | * -- TB6612 is a device of the TOSHIBA. |
jksoft | 0:810f315ba3dc | 5 | * |
jksoft | 0:810f315ba3dc | 6 | * Copyright (C) 2012 Junichi Katsu (JKSOFT) |
jksoft | 0:810f315ba3dc | 7 | */ |
jksoft | 0:810f315ba3dc | 8 | |
jksoft | 0:810f315ba3dc | 9 | |
jksoft | 0:810f315ba3dc | 10 | #include "TB6612.h" |
jksoft | 0:810f315ba3dc | 11 | |
jksoft | 0:810f315ba3dc | 12 | // TB6612 Class Constructor |
jksoft | 0:810f315ba3dc | 13 | TB6612::TB6612(PinName pwm, PinName fwd, PinName rev): |
jksoft | 0:810f315ba3dc | 14 | _pwm(pwm), _fwd(fwd), _rev(rev) { |
jksoft | 0:810f315ba3dc | 15 | |
jksoft | 0:810f315ba3dc | 16 | _fwd = 0; |
jksoft | 0:810f315ba3dc | 17 | _rev = 0; |
jksoft | 0:810f315ba3dc | 18 | _pwm = 0.0; |
jksoft | 0:810f315ba3dc | 19 | _pwm.period(0.001); |
jksoft | 0:810f315ba3dc | 20 | } |
jksoft | 0:810f315ba3dc | 21 | |
jksoft | 0:810f315ba3dc | 22 | // Speed Control |
jksoft | 0:810f315ba3dc | 23 | // arg |
jksoft | 1:051a7ecff13e | 24 | // int speed -100 -- 0 -- 100 |
jksoft | 1:051a7ecff13e | 25 | void TB6612::speed(int speed) { |
jksoft | 1:051a7ecff13e | 26 | |
jksoft | 1:051a7ecff13e | 27 | if( speed > 0 ) |
jksoft | 0:810f315ba3dc | 28 | { |
jksoft | 1:051a7ecff13e | 29 | _pwm = ((float)speed) / 100.0; |
jksoft | 0:810f315ba3dc | 30 | _fwd = 1; |
jksoft | 0:810f315ba3dc | 31 | _rev = 0; |
jksoft | 0:810f315ba3dc | 32 | } |
jksoft | 1:051a7ecff13e | 33 | else if( speed < 0 ) |
jksoft | 0:810f315ba3dc | 34 | { |
jksoft | 1:051a7ecff13e | 35 | _pwm = -((float)speed) / 100.0; |
jksoft | 0:810f315ba3dc | 36 | _fwd = 0; |
jksoft | 0:810f315ba3dc | 37 | _rev = 1; |
jksoft | 0:810f315ba3dc | 38 | } |
jksoft | 0:810f315ba3dc | 39 | else |
jksoft | 0:810f315ba3dc | 40 | { |
jksoft | 0:810f315ba3dc | 41 | _fwd = 1; |
jksoft | 0:810f315ba3dc | 42 | _rev = 1; |
jksoft | 0:810f315ba3dc | 43 | } |
jksoft | 0:810f315ba3dc | 44 | } |
jksoft | 0:810f315ba3dc | 45 | |
jksoft | 0:810f315ba3dc | 46 | |
jksoft | 0:810f315ba3dc | 47 | // Speed Control with time-out |
jksoft | 0:810f315ba3dc | 48 | // arg |
jksoft | 1:051a7ecff13e | 49 | // int speed -100 -- 0 -- 100 |
jksoft | 1:051a7ecff13e | 50 | // int time 0 |
jksoft | 1:051a7ecff13e | 51 | void TB6612::move(int sspeed , int time) |
jksoft | 0:810f315ba3dc | 52 | { |
jksoft | 0:810f315ba3dc | 53 | speed(sspeed); |
jksoft | 1:051a7ecff13e | 54 | wait_ms(time); |
jksoft | 0:810f315ba3dc | 55 | } |