Simple PWM for motor control

Dependencies:   mbed

This program is for motor control with Arduino motor shield and LCP 1768.

For motor control with arduino motor shield, it needs direction signal and brake signal. Maybe brake signal is optional. So, the code use three pins, direction(gpio), brake(gpio) and PWM output.

- Schematic /media/uploads/hjjeon/lpc1768_motor_shield_schem.jpg

Revision:
0:5f85a7752a04
Child:
1:4f47e58cd882
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 18 02:16:00 2014 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+
+#define FORWARD     0
+#define BACKWARD    1
+
+DigitalOut myled(LED1);
+
+int main() {
+        
+    Serial pc(USBTX, USBRX);
+    pc.baud(115200);
+    
+    PwmOut mypwm(p21);
+    DigitalOut direction(p5);
+    DigitalOut brake(p6);
+    
+    direction = FORWARD;// FORWARD == 0;.
+    
+    while(1) {
+        myled = !myled;
+        mypwm = mypwm + 0.05;
+        wait(3);
+        if( mypwm >= 1)
+        {
+            brake = 1; //stop
+        }
+    }
+}