Bearpi开发板HarmonyOS之PWM输出

news/2024/7/21 8:41:22 标签: harmonyos, Bearpi开发板, PWM

wifiiot_pwm.h接口简介

  1. 初始化PWM
    unsigned int PwmInit(WifiIotPwmPort port);
  2. 取消初始化PWM
    unsigned int PwmDeinit(WifiIotPwmPort port);
  3. 根据输入参数输出PWM
    unsigned int PwmStart(WifiIotPwmPort port, unsigned short duty, unsigned short freq);
  4. 停止PWM输出
    unsigned int PwmStop(WifiIotPwmPort port);

PWMLED_11">PWM驱动LED灯代码

#include <stdio.h>
#include <unistd.h>
#include "ohos_init.h"
#include <string.h>
#include "cmsis_os2.h"
#include "wifiiot_gpio.h"
#include "wifiiot_gpio_ex.h"
#include "wifiiot_pwm.h"

static void pwm2_func(void)
{
  // LED灯引脚配置成PWM输出
    GpioInit();
    IoSetFunc(WIFI_IOT_IO_NAME_GPIO_2,WIFI_IOT_IO_FUNC_GPIO_2_PWM2_OUT);
    GpioSetDir(WIFI_IOT_IO_NAME_GPIO_2,WIFI_IOT_GPIO_DIR_OUT);
    int i;
    
     //初时化PWM2
      PwmInit(WIFI_IOT_PWM_PORT_PWM2);
      while(1)
      {
         for (i = 0; i < 40000; i += 200)
        {
            //输出不同占空比的PWM
            PwmStart(WIFI_IOT_PWM_PORT_PWM2, i, 40000);

            usleep(10);
        }
       
       
      }
}

static void my_led_example(void)
{
   
     osThreadAttr_t attr;
     attr.attr_bits = 0;
     attr.name = "pwm2";
     attr.cb_mem = NULL;
     attr.cb_size = 0;
     attr.priority = 24;
     attr.stack_size = 512;

     if(osThreadNew((osThreadFunc_t)pwm2_func,NULL,&attr) == NULL)
     {
        printf("Falied to create PWMTask!\n");
    }
}

SYS_RUN(my_led_example);

运行效果

在这里插入图片描述


http://www.niftyadmin.cn/n/1226517.html

相关文章

ARM Mbed智能灯控

硬件 软件 介绍 照明和暖气是水电费中两个最重要的部分。 智能照明可以帮助降低成本。 在这个项目中&#xff0c;我们使用LED代表房间的光线&#xff0c;使用PIR&#xff08;被动红外&#xff09;传感器检测房间中是否有人&#xff0c;使用LDR&#xff08;光敏电阻&#xff…

Bearpi开发板HarmonyOS之ADC采样

wifiiot_adc.h接口简介 创建任务1秒读取一次ADC #include <stdio.h> #include <unistd.h> #include "ohos_init.h" #include <string.h> #include "cmsis_os2.h" #include "wifiiot_gpio.h" #include "wifiiot_gpio_ex.…

ARM Mbed声控门禁

硬件 软件 介绍 现代手机具有许多有用的功能&#xff0c;可以丰富您的物联网项目。 在这个项目中&#xff0c;我们将使用Android手机的语音识别功能&#xff0c;使语音控制器进入门禁。 我们将使用MIT App Inventor 2&#xff08;AI2&#xff09;开发电话应用程序&#xff0…

Bearpi开发板HarmonyOS之UART读写

wifiiot_uart.h中包含声明UART接口函数 初始化UART unsigned int UartInit(WifiIotUartIdx id, const WifiIotUartAttribute *param, const WifiIotUartExtraAttr *extraAttr);取消UART初始化 unsigned int UartDeinit(WifiIotUartIdx id);从UART读取数据 int UartRead(WifiIo…

MQTT消息控制车辆Python实践

现在&#xff0c;我们将使用Python作为主要的编程语言来生成将充当发布者和订阅者的MQTT客户端。 我们将Python MQTT客户端连接到MQTT服务器&#xff0c;并处理命令以使用MQTT消息控制小型车辆。 小型车辆具有现实道路车辆所具有的许多功能。 我们将使用TLS加密和TLS身份验证&…

Bearpi开发板HarmonyOS之 WiFi AP热点

wifi_hotspot.h接口简介 启用AP热点模式 WifiErrorCode EnableHotspot(void);禁用AP热点模式 WifiErrorCode DisableHotspot(void);设置指定的热点配置 WifiErrorCode SetHotspotConfig(const HotspotConfig* config);获取指定的热点配置 WifiErrorCode GetHotspotConfig(Hots…

Bearpi开发板HarmonyOS之WiFi STA联网

wifi_device.h接口简介 启用Wifi STA 模式 WifiErrorCode EnableWifi(void); 禁用Wifi STA 模式 WifiErrorCode DisableWifi(void); 检查Wifi STA模式是否启用 int IsWifiActive(void); 扫描热点信息 WifiErrorCode Scan(void); 获取所有扫描到的热点列表 WifiErrorCode Ge…

Raspberry Pi 与Arduino SPI通信

本教程介绍了使用SPI&#xff08;串行外围设备接口总线&#xff09;进行Raspberry Pi与Arduino通讯和控制的基本框架。 SPI代表了一种非常完善的芯片间通信方法&#xff0c;该方法在两种设备的硬件中均实现。 在这里&#xff0c;我们将详细探讨SPI&#xff0c;讨论硬件和软件注…