Create a motor object, to control a motor using L293DNE and FDRM-KL46z.

Dependencies:   mbed

Revision:
0:c542014a089d
Child:
1:4040dba1ef4c
diff -r 000000000000 -r c542014a089d Motor.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.cpp	Fri Aug 19 01:51:07 2016 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+#include "Motor.h"
+
+Motor::Motor(PinName Positive, PinName Negative,PinName Speed):
+        _positive(Positive), _negative(Negative), _speed(Speed) {
+     _speed.period(0.03f);      // 4 second period
+     _speed.write(0.20f); 
+}   
+     /* Input 1 or 2.
+     *  1 : Postive VCC Negtaive GND, 2 : Postive GND Negtaive VCC.
+     */
+void Motor::Direction(int move) {
+     if(move == 1){
+     _positive = 1;
+     _negative = 0;
+    }
+    else if(move == 2){   
+     _positive = 0;
+     _negative = 1;
+        }
+    }//End of Direction
+   
+     /* No input.
+     *  1 : Postive GND Negtaive GND  
+     */
+void Motor::Stop() {
+     _positive = 0;
+     _negative = 0;
+    }//End of Stop
+    
+void Motor::Speed(int motor_speed) {
+   float percantage = motor_speed/100;
+   _speed.write(percantage); 
+    }//End of Speed
\ No newline at end of file