Matthew Sims
/
Lab2DCControl
Lab 2 DC
Revision 0:ed96989f8478, committed 2015-10-13
- Comitter:
- mattsims12
- Date:
- Tue Oct 13 02:55:17 2015 +0000
- Commit message:
- Lab2 DC
Changed in this revision
--- /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
--- /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; + } +}
--- /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