/** 03_pwm_servo * This program moves the servo back and forth * within the full range of pulse width = 1.0 - 2.0 ms. * * Hardware requirements: * - FRDM-KL25Z board * - Servo connected to D3, +5V and GND */
/ 03_pwm_servo
- This program moves the servo back and forth
- within the full range of pulse width = 1.0 - 2.0 ms.
- Hardware requirements:
- - FRDM-KL25Z board
- - Servo connected to D3, +5V and GND
- /
Revision 0:fd545c26a4bf, committed 2015-10-22
- Comitter:
- icserny
- Date:
- Thu Oct 22 12:54:29 2015 +0000
- Commit message:
- First version
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 fd545c26a4bf main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Oct 22 12:54:29 2015 +0000 @@ -0,0 +1,27 @@ +/** 03_pwm_servo + * This program moves the servo back and forth + * within the full range of pulse width = 1.0 - 2.0 ms. + * + * Hardware requirements: + * - FRDM-KL25Z board + * - Servo connected to D3, +5V and GND + */ + +#include "mbed.h" +PwmOut servo(D3); + +int main() { + servo.period_ms(20); //Period = 20 ms (f=50 Hz) + while(true) { + for(int pw=1000; pw <= 2000; pw=pw+20) { + servo.pulsewidth_us(pw); //Set new servo position + wait_ms(200); + } + wait_ms(1000); //Wait before reverse direction + for(int pw=2000; pw >= 1000; pw=pw-20) { + servo.pulsewidth_us(pw); //Set new servo position + wait_ms(200); + } + wait_ms(1000); + } +} \ No newline at end of file
diff -r 000000000000 -r fd545c26a4bf mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Oct 22 12:54:29 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68 \ No newline at end of file