Control an H-Bridge using a PwmOut (enable) and two DigitalOuts (direction select)

Fork of Motor by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
miczyg
Date:
Thu May 07 09:45:03 2015 +0000
Parent:
2:f265e441bcd9
Child:
4:5370aae8ee3b
Commit message:
asda

Changed in this revision

Motor.cpp Show annotated file Show diff for this revision Revisions of this file
Motor.h Show annotated file Show diff for this revision Revisions of this file
--- a/Motor.cpp	Tue Nov 23 16:16:43 2010 +0000
+++ b/Motor.cpp	Thu May 07 09:45:03 2015 +0000
@@ -25,7 +25,8 @@
 #include "mbed.h"
 
 Motor::Motor(PinName pwm, PinName fwd, PinName rev):
-        _pwm(pwm), _fwd(fwd), _rev(rev) {
+    _pwm(pwm), _fwd(fwd), _rev(rev)
+{
 
     // Set initial condition of PWM
     _pwm.period(0.001);
@@ -36,9 +37,18 @@
     _rev = 0;
 }
 
-void Motor::speed(float speed) {
-    _fwd = (speed > 0.0);
-    _rev = (speed < 0.0);
+void Motor::speed(float speed)
+{
+    /*if(speed>0) {
+        _fwd = 1;
+        _rev = 0;
+    }
+    if(speed<0) {
+        _fwd = 0;
+        _rev = 1;
+    }*/
+    _fwd = 0;
+    _rev = 1;
     _pwm = abs(speed);
 }
 
--- a/Motor.h	Tue Nov 23 16:16:43 2010 +0000
+++ b/Motor.h	Thu May 07 09:45:03 2015 +0000
@@ -24,6 +24,7 @@
 #define MBED_MOTOR_H
 
 #include "mbed.h"
+#include "PID.h"
 
 /** Interface to control a standard DC motor 
  *
@@ -51,6 +52,9 @@
     DigitalOut _fwd;
     DigitalOut _rev;
 
+private:
+    //PID speedControl;
+
 };
 
 #endif