#include <stdio.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/gpio.h" #include "driver/ledc.h" #include "freertos/event_groups.h" #include "esp_log.h" EventGroupHandle_t Event_Group_Handle = NULL; //创建任务组 void Event_Group_Creat(){ Event_Group_Handle = xEventGroupCreate(); if(Event_Group_Handle!=NULL){ printf("YCP->Creat Success"); }else{ printf("YCP->Creat Fail"); } } void key_scan(void *ptr){ gpio_set_direction(GPIO_NUM_9,GPIO_MODE_INPUT); while(1){ //测试事件组,0x01就是标志位 if(gpio_get_level(GPIO_NUM_9)==0){ xEventGroupSetBits(Event_Group_Handle,0x01<<1); } vTaskDelay(1000/portTICK_PERIOD_MS); } } void test(void *ptr){ while (1){ EventBits_t r_event = xEventGroupWaitBits(Event_Group_Handle,0x01<<1,pdTRUE,pdFALSE,1000/portTICK_PERIOD_MS); if(r_event&(0x01<<1)){ ESP_LOGI("YCP","按键按下"); }else{ ESP_LOGI("YCP","按键没有按下"); } vTaskDelay(10000/portTICK_PERIOD_MS); } } void app_main(void){ led_init();//pwm初始化 Event_Group_Creat(); xTaskCreate(key_scan,"scan_name",2048,NULL,2,NULL); xTaskCreate(test,"test_name",2048,NULL,2,NULL); }
标签:Handle,freeRTOS,freertos,gpio,Group,include,Event From: https://www.cnblogs.com/ycp666/p/17015873.html