servo

Dependencies:   mbed Servo

main.cpp

Committer:
silviosz
Date:
2021-09-03
Revision:
2:10498697e83b
Parent:
1:40d2fd0b99e6
Child:
3:2848f736b75a

File content as of revision 2:10498697e83b:

// https://os.mbed.com/questions/1680/Analog-In-PWM-Out-to-control-rc-servo/
// 2021-08-26

#include "mbed.h"
PwmOut servo(D9);

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);        
    }
}