Henrique Rosa
/
TESTE_SERVO_OK
servo
Diff: main.cpp
- Revision:
- 2:10498697e83b
- Parent:
- 1:40d2fd0b99e6
- Child:
- 3:2848f736b75a
--- a/main.cpp Tue Nov 23 16:10:35 2010 +0000 +++ b/main.cpp Fri Sep 03 12:16:55 2021 +0000 @@ -1,13 +1,21 @@ -// Hello World to sweep a servo through its full range +// https://os.mbed.com/questions/1680/Analog-In-PWM-Out-to-control-rc-servo/ +// 2021-08-26 #include "mbed.h" -#include "Servo.h" - -Servo myservo(p21); +PwmOut servo(D9); -int main() { - for(float p=0; p<1.0; p += 0.1) { - myservo = p; - wait(0.2); +int main() + { + servo.period_us(20000); //20ms period, typical for analog RC servo + int servopulsewidth=1500; + servo.pulsewidth_us(servopulsewidth); //centers the servo. Usually a RC servos range is from 1000 to 2000us. + while(1) + { + //servo.pulsewidth_us(1500); //increments servopulsewidth with 1 + //wait(0.5); + servo.pulsewidth_us(1000); //increments servopulsewidth with 1 + wait(0.5); + servo.pulsewidth_us(2000); //increments servopulsewidth with 1 + wait(0.5); } -} +} \ No newline at end of file