|
鴻蒙Hi3861小視頻參賽:自家開發(fā)版上實現(xiàn)三色燈的變化, 這里使用的是hi3861 的三色燈板塊,實現(xiàn)的是三色燈的變換,可以設(shè)置三色燈變換的次數(shù),燈光變換的頻率。 代碼如下: #include<stdio.h> #include<unistd.h> #include “ohos_init.h“ #include “cmsis_os2.h“ #include “wifiiot_gpio.h“ #include “wifiiot_gpio_ex.h“ #include “wifiiot_pwm.h“ #include “wifiiot_adc.h“ #include “wifiiot_errno.h“ #define LED_DELAY_tiME_US 300000 #define LED_BRIGHT WIFI_IOT_GPIO_VALUE1 #define LED_DARK WIFI_IOT_GPIO_VALUE0 #define RED_LED_PIN_NAME WIFI_IOT_IO_NAME_GPIO_10 #define RED_LED_PIN_FUNCTION WIFI_IOT_IO_FUNC_GPIO_10_GPIO #define GREEN_LED_PIN_NAME WIFI_IOT_IO_NAME_GPIO_11 #define GREEN_LED_PIN_FUNCTION WIFI_IOT_IO_FUNC_GPIO_11_GPIO #define BLUE_LED_PIN_NAME WIFI_IOT_IO_NAME_GPIO_12 #define BLUE_LED_PIN_FUNCTION WIFI_IOT_IO_FUNC_GPIO_12_GPIO // 設(shè)置燈光的初始值 #define NUM_BLINKS 2 #define PWM_FREQ_DIVITION 64000 static void jltfcloudcom(void *arg) { (void)arg; IoSetFunc(RED_LED_PIN_NAME,WIFI_IOT_IO_FUNC_GPIO_10_PWM1_OUT); IoSetFunc(GREEN_LED_PIN_NAME,WIFI_IOT_IO_FUNC_GPIO_11_PWM2_OUT); IoSetFunc(BLUE_LED_PIN_NAME,WIFI_IOT_IO_FUNC_GPIO_12_PWM3_OUT); PwmInit(WIFI_IOT_PWM_PORT_PWM1); PwmInit(WIFI_IOT_PWM_PORT_PWM2); PwmInit(WIFI_IOT_PWM_PORT_PWM3); static const WifiIotGpioIdx pins[] = {RED_LED_PIN_NAME,GREEN_LED_PIN_NAME,BLUE_LED_PIN_NAME}; for(int i = 1 ; i <= NUM_BLINKS ; i++){ for(int i = 1 ; i <= PWM_FREQ_DIVITION ; i *= 2){ Pwmstart(WIFI_IOT_PWM_PORT_PWM1,i,PWM_FREQ_DIVITION); usleep(250000); PwmStop(WIFI_IOT_PWM_PORT_PWM1); } for(int i = 1 ; i <= PWM_FREQ_DIVITION ; i *= 2 ){ PwmStart(WIFI_IOT_PWM_PORT_PWM2,i,PWM_FREQ_DIVITION); usleep(250000); PwmStop(WIFI_IOT_PWM_PORT_PWM2); } for(int i = 1 ; i <= PWM_FREQ_DIVITION ; i *= 2){ PwmStart(WIFI_IOT_PWM_PORT_PWM3,i,PWM_FREQ_DIVITION); usleep(250000); PwmStop(WIFI_IOT_PWM_PORT_PWM3); } for(unsigned j = 0 ; j < sizeof(pins)/sizeof(pins[0]);j++){ GpioSetOutputVal(pins[j],LED_BRIGHT); usleep(LED_DELAY_TIME_US); GpioSetOutputVal(pins[j],LED_DARK); usleep(LED_DARK); } } } static void jltfcloudcn(void) { osThreadAttr_t attr; GpioInit(); attr.name=“jltfcloudcom“; attr.attr_bits=0U; attr.cb_mem=NULL; attr.cb_size=0U; attr.stack_mem=NULL; attr.stack_size=4096; attr.priority=osPriorityNormal; if(osThreadNew(jltfcloudcom,NULL,&attr) == NULL){ printf(“[jltfcloudcn] Failed to create jltfcloudcom!\n“); } } APP_FEATURE_INIT(jltfcloudcn); 以上功能實現(xiàn),參考了網(wǎng)絡(luò)上部分的公開代碼。 |
|