Library for H-Bridge Motor Driver Using Bipolar Transistors

Revision:
2:c1f9f9d74f35
Parent:
1:b690c5eb9469
--- a/motorlib.h	Tue Jan 15 13:33:21 2013 +0000
+++ b/motorlib.h	Sat Jan 26 15:00:23 2013 +0000
@@ -11,11 +11,20 @@
  
 #include "mbed.h"
  
+#define LM293D_MOTOR_CTRL 
 /** Interface to control a standard DC motor 
 * 
 */
 class Motor {
     public:
+    /** Motor Control Type */
+    enum MCtrlType {
+          L293D_DISCRETE   /**< 0 or 100% duty cycle with  L293D */
+        , L293D_PWM        /**< PWM based voltage control  with L293D */
+        , COMPS_DISCRETE   /**< 0 or 100% duty cycle with transistor circuit*/
+        , COMPS_PWM        /**< PWM based voltage control with transistor circuit*/       
+
+    };    
  
 /** Create a motor control interface    
 *
@@ -23,8 +32,10 @@
 * @param r2 DigitalOut, driving  H-bridge PNP transistor on the TOP right
 * @param r3 DigitalOut, driving  H-bridge NPN transistor on the BOTTOm left.
 * @param r4 DigitalOut, driving  H-bridge PNP transistor on the TOP left
+* @param mctype DigitalOut, driving  H-bridge PNP transistor on the TOP left
 */
-        Motor(PinName r1, PinName r2, PinName r3, PinName r4);
+       Motor(PinName r1, PinName r4,MCtrlType mctype =L293D_PWM);
+       Motor(PinName r1, PinName r2, PinName r3, PinName r4,MCtrlType mctype =L293D_PWM);
   
 /** Set the motor to coast/roll/off
 * 
@@ -57,10 +68,16 @@
         void stop(void);
    
     protected:
+      #ifdef LM293D_MOTOR_CTRL
+        PwmOut _r1;
+        PwmOut _r4;  
+      #else 
         DigitalOut _r1;
         DigitalOut _r2;
         DigitalOut _r3;
-        DigitalOut _r4;
+        DigitalOut _r4;      
+      #endif   
+        MCtrlType _mctype;
  
 };