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); }
Moter.cpp
- Committer:
- tichise
- Date:
- 2018-06-04
- Revision:
- 2:d6cb78f523b0
- Parent:
- 0:98dcc458e267
File content as of revision 2:d6cb78f523b0:
#include "Moter.h" Moter::Moter(PinName pwm, PinName in1, PinName in2):_pwm(pwm), _in1(in1), _in2(in2) { _in1 = 0; _in2 = 0; _pwm = 0.0; _pwm.period(0.001); } float Moter::speed(float speed) { if(speed > 0.0) { _pwm = speed; _in1 = 1; _in2 = 0; } else if(speed < 0.0) { _pwm = -speed; _in1 = 0; _in2 = 1; } else { _in1 = 1; _in2 = 1; } return speed == 0 ? 0 : speed > 0 ? 1 : -1; }