代码拉取完成,页面将自动刷新
本案例使用到了四组LED灯、蜂鸣器和按键。通过按键每次按下来控制不同的灯亮以及改变蜂鸣器的状态、实现蜂鸣器的鸣叫。
traffic_light_example.c --灯光和蜂鸣器控制源文件
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时,蜂鸣。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。