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:
- 15:b7ca53716b05
- Parent:
- 14:e66cf781f5b9
- Child:
- 16:afe936377d66
--- a/main.cpp Tue Nov 19 16:44:00 2019 +0000 +++ b/main.cpp Tue Nov 19 19:49:13 2019 +0000 @@ -1,7 +1,5 @@ //Enhancement 2// - #include "mbed.h" - //Status LED DigitalOut led(LED1); @@ -45,6 +43,7 @@ float dis; float trav =0; float speedA, speedB = 1.0f; +float paceA, paceB = 1.0f; void time() { //Reset timer and Start @@ -110,7 +109,32 @@ timer1.reset(); time(); } - + +void oneRPS () +{ + time(); + if (speedA <= 1.0f) + { + paceA +=0.01f; + wait_ms(25); + } + else if (speedA >= 1.0f) + { + paceA -=0.01f; + wait_ms(25); + } + else if (speedB <= 1.0f) + { + paceB +=0.01f; + wait_ms(25); + } + else if (speedB >= 1.0f) + { + paceB -=0.01f; + wait_ms(25); + } +} + int main() { @@ -175,28 +199,57 @@ PWMB.write(paceB); while(1) { - time(); - if (speedA <= 1.0f) - { - paceA +=0.01f; - wait_ms(25); - } - if (speedA >= 1.0f) - { - paceA -=0.01f; - wait_ms(25); - } - if (speedB <= 1.0f) - { - paceB +=0.01f; - wait_ms(25); - } - if (speedB >= 1.0f) - { - paceB -=0.01f; - wait_ms(25); - } - PWMA.write(paceA); - PWMB.write(paceA); + oneRPS(); + while(trav <= 1250) + { + PWMA.write(paceA); //Set duty cycle y + PWMB.write(paceB); + time(); + oneRPS(); + } + reset(); + while(trav <= 330) + { + PWMA.write(paceA); + PWMB.write(0.0f); + time(); + oneRPS(); + } + reset(); + while(trav <= 1457) + { + PWMA.write(paceA); + PWMB.write(paceB); + time(); + oneRPS(); + } + reset(); + while(trav <= 268) + { + PWMA.write(paceA); + PWMB.write(0.0f); + time(); + oneRPS(); + } + reset(); + while(trav <= 750) + { + PWMA.write(paceA); + PWMB.write(paceB); + time(); + oneRPS(); + } + reset(); + while(trav <= 200) + { + PWMA.write(paceA); + PWMB.write(0.0f); + time(); + oneRPS(); + } + timer.stop(); + break; } + PWMA.write(0.0f); + PWMB.write(0.0f); } \ No newline at end of file