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.
Diff: main.cpp
- Revision:
- 8:f2b6ef8c5eb8
- Parent:
- 7:9c77eca4158a
- Child:
- 9:45ae94cf5e23
--- a/main.cpp Thu Nov 14 16:55:17 2019 +0000 +++ b/main.cpp Tue Nov 19 12:17:42 2019 +0000 @@ -69,14 +69,13 @@ int tA1[2]; int tA2[2]; float dis; -float distance; +float trav =0; void time() { //Reset timer and Start timer.reset(); timer.start(); - //********************************************************************* //FIRST TIME - SYNCHRONISE (YOU SHOULD NOT NEED THIS ONCE IT's RUNNING) //********************************************************************* @@ -123,9 +122,9 @@ dis = timer1.read_us(); float mm = ((TA*3)*20.8)/175.9; - distance = dis/(mm); + trav = dis/(mm); float fA = 1.0f/ (TA *(float)3.0E-6); - terminal.printf("Average A2 Shaft: %6.2fHz \t Wheel: %6.2f \t distance: %6.2f\n", fA, fA/20.8f, distance); + terminal.printf("Average A2 Shaft: %6.2fHz \t Wheel: %6.2f \t trav: %6.2f\n", fA, fA/20.8f, trav); } int main() @@ -159,49 +158,45 @@ //Wait - give time to start running wait(1.0); - - - - //Main polling loop while(1) { - - while(distance <= 1250) + timer1.start(); + while(trav <= 1250) { PWMA.write(dutyA); //Set duty cycle y PWMB.write(dutyB); time(); } - while(distance <= 1331) + while(trav <= 1331) { - PWMA.write(0.0F); - PWMB.write(dutyB); + PWMA.write(dutyA); + PWMB.write(0.0f); time(); } - while(distance <= 2788) + while(trav <= 2788) { PWMA.write(dutyA); PWMB.write(dutyB); time(); } - while(distance <= 3544) + while(trav <= 3544) { - PWMA.write(0.0F); - PWMB.write(dutyB); + PWMA.write(dutyA); + PWMB.write(0.0f); time(); } - while(distance <= 4294) + while(trav <= 4294) { PWMA.write(dutyA); PWMB.write(dutyB); time(); } - while(distance <= 4963) + while(trav <= 4963) { - PWMA.write(0); - PWMB.write(dutyB); + PWMA.write(dutyA); + PWMB.write(0.0f); time(); }