Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DebounceIn mbed
Diff: main.cpp
- Revision:
- 1:357e2c6d4e66
- Parent:
- 0:f9546c3e2e72
- Child:
- 2:53177e0d0c43
--- a/main.cpp Tue May 26 19:46:52 2015 +0000 +++ b/main.cpp Mon Jul 13 23:17:35 2015 +0000 @@ -1,43 +1,83 @@ #include "mbed.h" +#include "DebounceIn.h" DigitalOut myled(LED1); //Indicator light to indicate the program is running -DigitalOut motor(D4); //To MOSFET -DigitalOut indic(LED2); //Indicate Hall ES State -DigitalIn hall(D6); //HFS (deprecated?) -DigitalIn swiRe(D1); //Rear Limit Switch -DigitalIn swiFr(D2); //Front Limit Switch +//PwmOut motor(D2); //To MOSFET +DigitalOut motor(D2); //Direct Drive the motor +DigitalOut indicRe(LED2); //Indicate Rear Switch State +DigitalOut indicFr(LED3); //Indicate Front Switch State +//DigitalOut indicHa(LED4); //Indicate Hall Switch State +DebounceIn swiRe(D5); //Rear Limit Switch +DebounceIn swiFr(D6); //Front Sensor Switch + +Timer t; //timer for last fr hit +int cuttFr = 1000; //ms time front +int cuttRe = 500; //ms time rear +bool prevSwi = 0; //previously hit switch -- 0 Re, 1 Fr +bool motorSo = 0; + +int count = 0; //count of cycles + int main() { myled = 1; - wait(0.2); - myled = 0; - wait(0.2); - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); - myled = 1; + wait(0.2); + myled = 0; + wait(0.2); + myled = 1; + wait(0.2); + myled = 0; + wait(0.2); + myled = 1; + t.start(); + printf("Start!\n"); while(1) { - if (swiRe&&(~swiFr)){ - motor = 1; - indic = 1; + if (swiFr){ + indicFr = 0; + wait(.75); + if (swiRe==0){ + indicFr = 0; + indicRe = 1; + /* + myled = 0; + motor.write(0.25f); + wait(.2); + motor.write(0.35f); + wait(.2); + motor.write(0.45f); + wait(.2); + motor.write(0.55f); + wait(.1); + motor.write(0.65f); + wait(.1); + motor.write(0.75f); + wait(.1); + motor.write(0.85f); + wait(.1); + motor.write(0.95f); + wait(.1); + motor.write(1.00f); + } */ + motor = 1;} + while (swiRe==0){ + indicFr = 0; + indicRe = 1; + myled = 0; + //motor.write(1.00f); + } + indicRe = 0; + indicFr = 1; + myled = 1; + //wait(1); + motor= 0; + count++; + printf("Motor State Switch!! %d cycles \n",count); } - - if((~swiRe)&&swiFr){ - motor = 0; - indic = 0; + else { + indicRe = 1; + indicFr = 1; } - //if (hall==1){ - // motor = 1; - // indic = 1; - // } - //if (hall == 0) { - // motor= 0; - // indic = 0; - // } - - - - + } } +