PWM 操作,先设置频率(周期的s数) 再写入占空比即可
#include "mbed.h"
PwmOut led(PB_0);
int main()
{
// specify period first
led.period(4.0f); // 4.0f = 4 second period
led.write(0.50f); // 50% duty cycle, relative to period 0=high 1=low
//led = 0.5f; // shorthand for led.write()
//led.pulsewidth(2); // alternative to led.write, set duty cycle time in seconds
while (1);
}
网友评论