John Mc
/
Quad_PWM
IoTT Quad Control
Fork of frdm_rgbled by
- PTD0 to Motor 1
- PTD1 to Motor 2
- PTD2 to Motor 3
- PTD3 to Motor 4
- D2 to Digital Motion Sensor (I used https://developer.mbed.org/components/Grove-PIR-Motion-Sensor/)
Revision 8:e282aa7c1fe9, committed 2015-10-06
- Comitter:
- johnmc
- Date:
- Tue Oct 06 20:40:58 2015 +0000
- Parent:
- 7:ad8295723268
- Commit message:
- IoTT Quad;
Changed in this revision
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 ad8295723268 -r e282aa7c1fe9 main.cpp --- a/main.cpp Wed Jul 16 10:20:45 2014 +0000 +++ b/main.cpp Tue Oct 06 20:40:58 2015 +0000 @@ -1,19 +1,71 @@ #include "mbed.h" -PwmOut r(LED_RED); -PwmOut g(LED_GREEN); +Serial pc(USBTX,USBRX); + +PwmOut M1(PTD0); +PwmOut M2(PTD1); +PwmOut M3(PTD2); +PwmOut M4(PTD3); + +//LED Outs +DigitalOut led_red(LED_RED); +DigitalOut led_green(LED_GREEN); + +DigitalIn motion(D2); int main() { - r.period(0.001f); - g.period(0.001f); - + pc.printf("Loading...\n\r"); + pc.printf("%c\n\r",motion); + M1.period(0.0025f); + M2.period(0.0025f); + M3.period(0.0025f); + M4.period(0.0025f); +//Motor Off + M1.write(0.0f); + M2.write(0.0f); + M3.write(0.0f); + M4.write(0.00f); + led_red = 1; + led_green = 0; + wait (2.0f); +//Wait for Motion while (true) { - for (float i = 0.0f; i < 1.0f ; i += 0.001f) { - float p = 3 * i; - r = 1.0f - ((p < 1.0f) ? 1.0f - p : (p > 2.0f) ? p - 2.0f : 0.0f); - g = 1.0f - ((p < 1.0f) ? p : (p > 2.0f) ? 0.0f : 2.0f - p); - wait (0.0025f); - } + led_red = 1; + led_green = 0; + pc.printf("Motors off; Waiting for motion...\n\r"); +//Motor Off + M1.write(0.0f); + M2.write(0.0f); + M3.write(0.0f); + M4.write(0.0f); + wait (.0025f); + if(motion){ + pc.printf("Motors On"); + led_red = 0; + led_green = 1; + M1.write(0.5f); //Anything less than 50% duty cycle did not spin my motors. + M2.write(0.5f); + M3.write(0.5f); + M4.write(0.5f); + wait (.0025f); + } + //RAMP DOWN SEQUENCE to avoid ESC protection + M1.write(0.25f); + M2.write(0.25f); + M3.write(0.25f); + M4.write(0.25f); + wait (.0025f); + M1.write(0.15f); + M2.write(0.15f); + M3.write(0.15f); + M4.write(0.15f); + wait (.0025f); + M1.write(0.0f); + M2.write(0.0f); + M3.write(0.0f); + M4.write(0.0f); + wait (.0025f); + } } -} +
diff -r ad8295723268 -r e282aa7c1fe9 mbed.bld --- a/mbed.bld Wed Jul 16 10:20:45 2014 +0000 +++ b/mbed.bld Tue Oct 06 20:40:58 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa \ No newline at end of file