Example to sweep a servo through its range
Fork of Servo_HelloWorld by
Revision 2:7911e5580e4e, committed 2015-07-24
- Comitter:
- woyao74le
- Date:
- Fri Jul 24 12:19:29 2015 +0000
- Parent:
- 1:40d2fd0b99e6
- Commit message:
- Servo test
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 40d2fd0b99e6 -r 7911e5580e4e main.cpp --- a/main.cpp Tue Nov 23 16:10:35 2010 +0000 +++ b/main.cpp Fri Jul 24 12:19:29 2015 +0000 @@ -1,13 +1,24 @@ // Hello World to sweep a servo through its full range #include "mbed.h" -#include "Servo.h" + +PwmOut PWM1(PA_1); -Servo myservo(p21); +int main() +{ -int main() { - for(float p=0; p<1.0; p += 0.1) { - myservo = p; - wait(0.2); + PWM1.period(0.02); + while(1) + { + for (float i=0.025; i<0.04; i=i+0.001) + { + PWM1=i; + wait(0.02); + } + for (float i=0.04; i>0.025; i=i-0.001) + { + PWM1=i; + wait(0.02); + } } }
diff -r 40d2fd0b99e6 -r 7911e5580e4e mbed.bld --- a/mbed.bld Tue Nov 23 16:10:35 2010 +0000 +++ b/mbed.bld Fri Jul 24 12:19:29 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e +http://mbed.org/users/mbed_official/code/mbed/builds/da0ca467f8b5 \ No newline at end of file