Lab 2 DC

Dependencies:   Motor mbed

Revision:
0:ed96989f8478
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 13 02:55:17 2015 +0000
@@ -0,0 +1,33 @@
+/*Matthew Sims
+  DC Control
+  Moves Speeds a dc motor and changes its direction every time it speeds up. At full speed, it slows down.
+  10/13/15
+*/
+
+#include "mbed.h"       //include libraries
+#include "Motor.h"
+
+Motor m(p25,p27,p28);   //Set up motor
+
+int main()
+{
+    int direction=1;     //tracks which way motor is turning
+    int tracker=1;       //Tracks if speed is increasing or decreasing
+    float speed=.2;      //speed of motor
+
+    while(1) {
+        getchar();              //Wait for button press
+
+        if(tracker==1)          //Add .2 to absolute value of speeed
+            speed+=.2;
+        else
+            speed-=.2;
+        direction*=-1;         //Direction changes after every speed change
+        if (direction==1)
+            m.speed(speed);
+        else
+            m.speed(-1*speed);
+        if(speed==1.0 || speed<0.1)  //If it reaches maximum speed, It will start decresing, if minimum, it will incrcease.
+            tracker*=-1;
+    }
+}