TI_TB6612FNG is a library of TB6612FNG.

Dependents:   TI_TB6612FNG_SAMPLE

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);
}

Files at this revision

API Documentation at this revision

Comitter:
tichise
Date:
Mon Jun 04 23:14:18 2018 +0000
Commit message:
new

Changed in this revision

Moter.cpp Show annotated file Show diff for this revision Revisions of this file
Moter.h Show annotated file Show diff for this revision Revisions of this file
TI_TB6612FNG.cpp Show annotated file Show diff for this revision Revisions of this file
TI_TB6612FNG.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 982bd54e15b1 Moter.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Moter.cpp	Mon Jun 04 23:14:18 2018 +0000
@@ -0,0 +1,28 @@
+#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;
+}
\ No newline at end of file
diff -r 000000000000 -r 982bd54e15b1 Moter.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Moter.h	Mon Jun 04 23:14:18 2018 +0000
@@ -0,0 +1,25 @@
+#ifndef MBED_MOTER_H
+#define MBED_MOTER_H
+
+#include "mbed.h"
+
+class Moter
+{
+
+public:
+
+    Moter(PinName pwm, PinName in1, PinName in2);
+
+    float speed(float speed);
+
+    void operator = ( float value ) {
+        speed(value);
+    }
+
+protected:
+    PwmOut _pwm;
+    DigitalOut _in1;
+    DigitalOut _in2;
+};
+
+#endif
diff -r 000000000000 -r 982bd54e15b1 TI_TB6612FNG.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TI_TB6612FNG.cpp	Mon Jun 04 23:14:18 2018 +0000
@@ -0,0 +1,47 @@
+#include "TI_TB6612FNG.h"
+#include "mbed.h"
+
+TI_TB6612FNG::TI_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 TI_TB6612FNG::stop()
+{
+    _motorL = 0;
+    _motorR = 0;
+    _isForward = false;
+}
+
+void TI_TB6612FNG::forward(float speed)
+{
+    _motorL = speed;
+    _motorR = speed;
+    _isForward = true;
+}
+
+void TI_TB6612FNG::backward(float speed)
+{
+    _motorL = -1*speed;
+    _motorR = -1*speed;
+    _isForward = false;
+}
+
+void TI_TB6612FNG::left(float speed)
+{
+    _motorL = -1*speed;
+    _motorR = speed;
+    _isForward = false;
+}
+
+void TI_TB6612FNG::right(float speed)
+{
+    _motorL = speed;
+    _motorR = -1*speed;
+    _isForward = false;
+}
+
+bool TI_TB6612FNG::isForward() {
+    return _isForward;
+}
\ No newline at end of file
diff -r 000000000000 -r 982bd54e15b1 TI_TB6612FNG.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TI_TB6612FNG.h	Mon Jun 04 23:14:18 2018 +0000
@@ -0,0 +1,26 @@
+#ifndef MBED_TI_TB6612FNG_H
+#define MBED_TI_TB6612FNG_H
+
+#include "mbed.h"
+#include "Moter.h"
+
+class TI_TB6612FNG
+{
+public:
+    TI_TB6612FNG(PinName pwma, PinName ain1, PinName ain2, PinName pwmb, PinName bin1, PinName bin2, PinName standby);
+    void stop();
+    void forward(float speed);
+    void backward(float speed);
+    void left(float speed);
+    void right(float speed);
+    bool isForward();
+
+private:
+    Moter _motorL;
+    Moter _motorR;
+    DigitalOut _standby;
+
+    bool _isForward;
+};
+
+#endif