具体工程已上传至CSDN我的资源里,可直接免费下载
led.h:
#ifndef _LED_H_
#define _LED_H_
//定义LED灯的IO口
#define LED_RED_IO 46 //对应红灯的LED
//定义LED状态
#define LED_ON 0 //LED灯亮电平为低电平
#define LED_OFF 1 //LED灯灭电平为高电平
//控制红灯
void led_red(int on);
//LED初始化
void initLed();
#endif
led.c:
#include "driver/gpio.h"
#include "led.h"
//控制红灯
void led_red(int on)
{
if(on==LED_ON)
{
gpio_set_level(LED_RED_IO, LED_ON);//开灯
}
else
{
gpio_set_level(LED_RED_IO, LED_OFF);//关灯
}
}
//LED初始化
void initLed()
{
//初始化彩灯的IO口,
//红灯:GPIO
esp_rom_gpio_pad_select_gpio(LED_RED_IO);
gpio_set_direction(LED_RED_IO, GPIO_MODE_OUTPUT);
//开灯
led_red(LED_ON);
}
app_main.c:
#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_log.h"
#include "esp_system.h"
#include "spi_flash_mmap.h "
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_err.h"
#include "nvs_flash.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/ledc.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "string.h"
#include "led.h"
//用户函数入口,相当于main函数
void app_main(void)
{
int time=100;
initLed();//LED IO口初始化
while(1)
{
led_red(LED_ON);//打开红灯
vTaskDelay(time); //延时
led_red(LED_OFF);//关闭红灯
vTaskDelay(time); //延时
}
}