Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
TB6612.cpp@3:f70ecf1e21d5, 2019-11-23 (annotated)
- Committer:
- KINU
- Date:
- Sat Nov 23 10:06:03 2019 +0000
- Revision:
- 3:f70ecf1e21d5
moterCameraUS015sb612
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KINU | 3:f70ecf1e21d5 | 1 | /** |
KINU | 3:f70ecf1e21d5 | 2 | * Motor Driver TB6612 Control Library |
KINU | 3:f70ecf1e21d5 | 3 | * |
KINU | 3:f70ecf1e21d5 | 4 | * -- TB6612 is a device of the TOSHIBA. |
KINU | 3:f70ecf1e21d5 | 5 | * |
KINU | 3:f70ecf1e21d5 | 6 | * Copyright (C) 2012 Junichi Katsu (JKSOFT) |
KINU | 3:f70ecf1e21d5 | 7 | */ |
KINU | 3:f70ecf1e21d5 | 8 | |
KINU | 3:f70ecf1e21d5 | 9 | |
KINU | 3:f70ecf1e21d5 | 10 | #include "TB6612.h" |
KINU | 3:f70ecf1e21d5 | 11 | |
KINU | 3:f70ecf1e21d5 | 12 | // TB6612 Class Constructor |
KINU | 3:f70ecf1e21d5 | 13 | TB6612::TB6612(PinName pwm, PinName fwd, PinName rev): |
KINU | 3:f70ecf1e21d5 | 14 | _pwm(pwm), _fwd(fwd), _rev(rev) { |
KINU | 3:f70ecf1e21d5 | 15 | |
KINU | 3:f70ecf1e21d5 | 16 | _fwd = 0; |
KINU | 3:f70ecf1e21d5 | 17 | _rev = 0; |
KINU | 3:f70ecf1e21d5 | 18 | _pwm = 0.0; |
KINU | 3:f70ecf1e21d5 | 19 | _pwm.period(0.001); |
KINU | 3:f70ecf1e21d5 | 20 | } |
KINU | 3:f70ecf1e21d5 | 21 | |
KINU | 3:f70ecf1e21d5 | 22 | // Speed Control |
KINU | 3:f70ecf1e21d5 | 23 | // arg |
KINU | 3:f70ecf1e21d5 | 24 | // int speed -100 -- 0 -- 100 |
KINU | 3:f70ecf1e21d5 | 25 | void TB6612::speed(int speed) { |
KINU | 3:f70ecf1e21d5 | 26 | |
KINU | 3:f70ecf1e21d5 | 27 | if( speed > 0 ) |
KINU | 3:f70ecf1e21d5 | 28 | { |
KINU | 3:f70ecf1e21d5 | 29 | _pwm = ((float)speed) / 100.0; |
KINU | 3:f70ecf1e21d5 | 30 | _fwd = 1; |
KINU | 3:f70ecf1e21d5 | 31 | _rev = 0; |
KINU | 3:f70ecf1e21d5 | 32 | } |
KINU | 3:f70ecf1e21d5 | 33 | else if( speed < 0 ) |
KINU | 3:f70ecf1e21d5 | 34 | { |
KINU | 3:f70ecf1e21d5 | 35 | _pwm = -((float)speed) / 100.0; |
KINU | 3:f70ecf1e21d5 | 36 | _fwd = 0; |
KINU | 3:f70ecf1e21d5 | 37 | _rev = 1; |
KINU | 3:f70ecf1e21d5 | 38 | } |
KINU | 3:f70ecf1e21d5 | 39 | else |
KINU | 3:f70ecf1e21d5 | 40 | { |
KINU | 3:f70ecf1e21d5 | 41 | _fwd = 1; |
KINU | 3:f70ecf1e21d5 | 42 | _rev = 1; |
KINU | 3:f70ecf1e21d5 | 43 | } |
KINU | 3:f70ecf1e21d5 | 44 | } |
KINU | 3:f70ecf1e21d5 | 45 | |
KINU | 3:f70ecf1e21d5 | 46 | |
KINU | 3:f70ecf1e21d5 | 47 | // Speed Control with time-out |
KINU | 3:f70ecf1e21d5 | 48 | // arg |
KINU | 3:f70ecf1e21d5 | 49 | // int speed -100 -- 0 -- 100 |
KINU | 3:f70ecf1e21d5 | 50 | // int time 0 |
KINU | 3:f70ecf1e21d5 | 51 | void TB6612::move(int sspeed , int time) |
KINU | 3:f70ecf1e21d5 | 52 | { |
KINU | 3:f70ecf1e21d5 | 53 | speed(sspeed); |
KINU | 3:f70ecf1e21d5 | 54 | wait_ms(time); |
KINU | 3:f70ecf1e21d5 | 55 | } |
KINU | 3:f70ecf1e21d5 | 56 | |
KINU | 3:f70ecf1e21d5 | 57 |