Lab 2 DC

Dependencies:   Motor mbed

Files at this revision

API Documentation at this revision

Comitter:
mattsims12
Date:
Tue Oct 13 02:55:17 2015 +0000
Commit message:
Lab2 DC

Changed in this revision

Motor.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ed96989f8478 Motor.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.lib	Tue Oct 13 02:55:17 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Motor/#f265e441bcd9
diff -r 000000000000 -r ed96989f8478 main.cpp
--- /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;
+    }
+}
diff -r 000000000000 -r ed96989f8478 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 13 02:55:17 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file