Single direction, PWM control of a DC Motor

Dependencies:   Motor mbed tsi_sensor

Revision:
0:a19ecb0b5364
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Nov 30 13:06:59 2015 +0000
@@ -0,0 +1,33 @@
+#include "mbed.h"
+#include "tsi_sensor.h"
+ 
+
+TSIAnalogSlider tsi(PTB16, PTB17, 25);  // Touch pad slider tied to touch pad pins, named tsi
+PwmOut mSpeed(PTB0);
+DigitalOut DirCon1(PTC1);
+Serial pc(USBTX, USBRX);                    // USB Serial Port
+
+float readValue;
+float speed = 0;
+
+int main() 
+{
+    mSpeed.period(0.001);
+    
+    while(1)
+    {
+        pc.printf("\033[2J");   // Clear Screen and Home cursor
+        pc.printf("\033[H");  
+        readValue = tsi.readPercentage();
+        pc.printf("TSI = %0.2f\n\r", readValue);
+        if ( readValue == 0 )
+        {
+            mSpeed = 0;
+            DirCon1 = 0;
+            wait(0.2);
+        }
+        DirCon1 = 0;
+        mSpeed = readValue;
+        wait(0.2);
+    }
+}