liang brain / Mbed 2 deprecated Ex_IO_pwm

Dependencies:   mbed

main.cpp

Committer:
brainliang
Date:
2019-03-16
Revision:
0:d0c188d2cd1c

File content as of revision 0:d0c188d2cd1c:

/*
用普通IO模拟输出PWM
*/

#include "mbed.h"
#include "IO_pwm.h"

DigitalOut my_led(PC_13);
IO_pwm my_pwm(PA_5); // IO used by pwm_io function
int main() {
    
    my_pwm.pwm_io(20000, 0.075); // 20ms - 25%,舵机控制周期20ms占空比范围0.025--0.125
    
    while(1) {
        my_pwm.pwm_io(20000, 0.025); // 20ms - 2.5%
        my_led = !my_led;
        wait(0.5);
        my_pwm.pwm_io(20000, 0.125); // 20ms - 12.5%
        wait(0.5);
    }
}