Hiroshi SAKAMOTO
/
_test_servo
test servo
Revision 0:6d8bbd43c8e8, committed 2014-01-14
- Comitter:
- hayashiisme
- Date:
- Tue Jan 14 08:31:05 2014 +0000
- Commit message:
- test servo
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 000000000000 -r 6d8bbd43c8e8 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jan 14 08:31:05 2014 +0000 @@ -0,0 +1,25 @@ +#include "mbed.h" + +PwmOut servo1(p21); +PwmOut servo2(p22); + +#define waitsec 0.04 +#define start 900 +#define end 190 + +int main(){ + servo1.period_ms(20); // servo requires a 20ms period + servo2.period_ms(20); // servo requires a 20ms period + for(int i=0; i < 5; i++){ + for(int i = start; i < end; i += 10) { + servo1.pulsewidth_us(i); // servo position determined by a pulsewidth between 1-2ms + servo2.pulsewidth_us(i); // servo position determined by a pulsewidth between 1-2ms + wait(waitsec); + } + for(int i = end; i > start; i -= 10) { + servo1.pulsewidth_us(i); // servo position determined by a pulsewidth between 1-2ms + servo2.pulsewidth_us(i); // servo position determined by a pulsewidth between 1-2ms + wait(waitsec); + } + } +}
diff -r 000000000000 -r 6d8bbd43c8e8 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jan 14 08:31:05 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file