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