AF_TB6612FNG is a library of TB6612FNG.
Example
include the mbed library with this snippet
#include "mbed.h" #include "AF_TB6612FNG.h" AF_TB6612FNG tb6612fng(p21, p20, p19, p22, p18, p17, p12); int main() { float speed = 0.6; tb6612fng.forward(speed); }
Diff: AF_TB6612FNG.cpp
- Revision:
- 0:98dcc458e267
- Child:
- 2:d6cb78f523b0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AF_TB6612FNG.cpp Mon Jun 04 00:23:18 2018 +0000 @@ -0,0 +1,48 @@ +#include "AF_TB6612FNG.h" +#include "mbed.h" + +AF_TB6612FNG::AF_TB6612FNG(PinName pwma, PinName ain1, PinName ain2, PinName pwmb, PinName bin1, PinName bin2, PinName standby) + : _motorL(pwma,ain1,ain2),_motorR(pwmb,bin1,bin2),_standby(standby) { + _isForward = false; + _standby = 1; +} + +void AF_TB6612FNG::stop() +{ + _motorL = 0; + _motorR = 0; +} + +void AF_TB6612FNG::forward(float speed) +{ + _motorL = speed; + _motorR = speed; + _isForward = true; +} + +void AF_TB6612FNG::back(float speed) +{ + _motorL = -1*speed; + _motorR = -1*speed; + _isForward = true; +} + +void AF_TB6612FNG::left(float speed) +{ + _motorL = -1*speed; + _motorR = speed; +} + +void AF_TB6612FNG::right(float speed) +{ + _motorL = speed; + _motorR = -1*speed; +} + +void AF_TB6612FNG::setISForward(bool isForward) { + _isForward = isForward; +} + +bool AF_TB6612FNG::isForward() { + return _isForward; +} \ No newline at end of file