PWM操作

引入头文件

  #include "utils/PWMHelper.h"

具体操作

  #include "utils/PWMHelper.h"

  static void testPwm() {
    /**
     * 参数1: 端口号
     * 参数2: 频率
     * 参数3: 占空比
     * 参数4: 极性
     *
     * 默认是使能状态
     */
    PWMHelper pwm(0, 2500, 50, 0);

    // 以下延时用于测试设置后的效果
    usleep(50000);

    // 设置频率
    pwm.setFreq(2700);
    // 设置占空比
    pwm.setDuty(100);
    usleep(50000);

    // 关闭
    pwm.setEnable(false);
    usleep(50000);

    // 打开
    pwm.setEnable(true);
    usleep(50000);
  }
powered by Gitbooklast modified: 2022-08-24 10:20:04

results matching ""

    No results matching ""