a dc_motor drive lib use two PWM IO to drive the dc_motor

Dependents:   Nucleo_F411RE_OS_Robot_Tank

Revision:
0:cd71771d494f
Child:
1:d31307e787fd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motodriver.cpp	Tue Jun 19 08:50:21 2018 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+#include "motodriver.h"
+
+Motor::Motor(PinName pwm1pin, PinName pwm2pin) : _pwm1(pwm1pin) , _pwm2(pwm2pin)
+{
+    init();    
+}
+
+void Motor::init()
+{
+    // Set initial condition of PWM
+    _pwm1.period(0.001);
+    _pwm1 = 0;
+    
+    // Set initial condition of PWM
+    _pwm2.period(0.001);
+    _pwm2 = 0;
+}
+
+float Motor::Speed(float speed)
+{
+    float temp;
+    temp = abs(speed);
+    
+    if (speed > 0.0)
+    {
+        _pwm1 = temp;
+        _pwm2 = 0;
+    }
+    else
+    {
+        _pwm1 = 0;
+        _pwm2 = temp;
+    }
+    
+    return temp;
+}
+
+void Motor::Stop()
+{
+    _pwm1 = 0;
+    _pwm2 = 0;
+}
\ No newline at end of file