. └── applications └── sample └── wifi-iot └── app │── led │ │── led.c │ └── BUILD.gn └── BUILD.gn |
#include <stdio.h> #include <unistd.h> #include "ohos_init.h" #include "cmsis_os2.h" #include "wifiiot_gpio.h" #include "wifiiot_gpio_ex.h" #define LED_ON_TIME_US 2000000 #define LED_OFF_TIME_US 1000000 static void Led(void) { //GPIO引脚初始化 GpioInit(); //设置管脚功能为GPIO IoSetFunc(WIFI_IOT_IO_NAME_GPIO_9,WIFI_IOT_IO_FUNC_GPIO_9_GPIO); //设置GPIO引脚方向为输出 GpioSetDir(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_GPIO_DIR_OUT); while (1) { //设置GPIO09输出为低电平 GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, 0); //打印输出日志 printf("[DEMO] LED on. "); //延时一定时间,即亮灯的持续时间 usleep(LED_ON_TIME_US); //设置GPIO09输出为高电平 GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, 1); //打印输出日志 printf("[DEMO] LED off. "); //延时一定时间,即灭灯的持续时间 usleep(LED_OFF_TIME_US); } } SYS_RUN(Led); |
static_library("bahuyang") { sources = [ "led.c" include_dirs = [ "//utils/native/lite/include", "//kernel/liteos_m/components/cmsis/2.0", "//base/iot_hardware/interfaces/kits/wifiiot_lite", } |