17 Star 59 Fork 24

Talkweb_OpenHarmony / Niobe

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 2.80 KB
一键复制 编辑 原始数据 按行查看 历史
候鹏飞 提交于 2021-10-22 13:59 . update OpenHarmony 3.0 LTS

OpenHarmony模组开发-灯光控制和蜂鸣器使用

本案例使用到了四组LED灯、蜂鸣器和按键。通过按键每次按下来控制不同的灯亮以及改变蜂鸣器的状态、实现蜂鸣器的鸣叫。

目录结构:

src

traffic_light_example.c            --灯光和蜂鸣器控制源文件

相关API介绍

traffic_light_example demo

IoTWatchDogDisable: 关闭看门狗函数

IoTGpioInit(unsigned int id): 初始化GPIO
	参数说明:
	–id Indicates the GPIO pin number.
	
IoTIoSetFunc(IOT_GPIO_IO_NAME id, unsigned char val):	注册功能
	参数说明:
	-id Indicates the GPIO pin number.
	-val 复用功能
	
IoTGpioSetDir(unsigned int id, IotGpioDir dir):Sets the direction for a GPIO pin.
	参数说明:
	-id Indicates the GPIO pin number.
	-dir IO方向
	
IotIoSetPull(IOT_GPIO_IO_NAME id, IOT_IO_PULL val):设置GPIO为上拉或下拉
	参数说明:
	-id Indicates the GPIO pin number.
	-val 上拉或下拉	
	
IoTGpioRegisterIsrFunc(unsigned int id, IotGpioIntType intType, IotGpioIntPolarity intPolarity, GpioIsrCallbackFunc func, char *arg):	Enables the interrupt feature for a GPIO pin.
	参数说明:
	-id Indicates the GPIO pin number.
	-intType Indicates the interrupt type.
	-intPolarity Indicates the interrupt polarity.
	-func Indicates the interrupt callback function.
	-arg Indicates the pointer to the argument used in the interrupt callback function.
	
IoTGpioSetOutputVal(unsigned int id, IotGpioValue val):Sets the output level value for a GPIO pin.
	参数说明:
	-id	Indicates the GPIO pin number.
	-val Indicates the output level value.
	
IoTPwmInit(unsigned int port): Initializes a PWM device.
	参数说明:
	-port Indicates the port number of the PWM device
	
osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr_t *attr):Creates an active thread. 
	参数说明:
	-func Indicates the entry of the thread callback function.
	-argument Indicates the pointer to the argument passed to the thread.
	-attr Indicates the thread attributes.	
	
IoTPwmStart(unsigned int port, unsigned short duty, unsigned int freq):Starts PWM signal output from a specified port based on the given output frequency and duty cycle.
	参数说明:
	-port Indicates the port number of the PWM device.
	-duty Indicates the duty cycle for PWM signal output. The value ranges from 1 to 99.
	-freq Indicates the frequency for PWM signal output.
	
IoTPwmStop(unsigned int port):Stops PWM signal output from a specified port.
	参数说明:
	-port Indicates the port number of the PWM device.		

运行结果

先每个灯闪烁一下,亮2秒灭1秒,2遍,测试4个灯是否正常。
按键每按下一次,切换一次灯亮同时改变蜂鸣器状态,蜂鸣器状态为1时,蜂鸣。
1
https://gitee.com/talkweb_oh/niobe.git
git@gitee.com:talkweb_oh/niobe.git
talkweb_oh
niobe
Niobe
master

搜索帮助