本帖最后由 游走在01的海洋 于 2021-8-8 20:15 编辑
一、示范
1.简介:使用blink例程,引脚改为IO6,其他不变
2.图片:硬件---开发板、面包板、杜邦线、LED灯
3.视频(没有添加成功,有兴趣的看百度云盘)
链接:https://pan.baidu.com/s/1OaCSTNcTlfzbRb9_q9OPIQ
提取码:8wj0
二、代码
1.历程blink,IO口改为6,添加注释
- #define BLINK_GPIO 6//CONFIG_BLINK_GPIO //使用宏BLINK_GPIO设置对应IO口
- void app_main(void)
- {
- /* Configure the IOMUX register for pad BLINK_GPIO (some pads are
- muxed to GPIO on reset already, but some default to other
- functions and need to be switched to GPIO. Consult the
- Technical Reference for a list of pads and their default
- functions.)
- */
- gpio_reset_pin(BLINK_GPIO); //将BLINK_GPIO所对应的IO恢复默认状态
- /* Set the GPIO as a push/pull output */
- gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); //配置IO口引脚,
- while(1) {
- /* Blink off (output low) */
- printf("Turning off the LEDn");
- gpio_set_level(BLINK_GPIO, 0); //设置IO口引脚拉低
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- /* Blink on (output high) */
- printf("Turning on the LEDn");
- gpio_set_level(BLINK_GPIO, 1); //设置IO口引脚拉高
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- }
- }
硬件连接好之后;在ESP-IDF命令工具中编译、下载,可以看到LED闪烁;
2.各个GPIO函数的定义解释
1)gpio_reset_pin
2)gpio_set_direction(gpio_num_t gpio_num, gpio_mode_t mode);
3) gpio_set_level
三、使用VS code中的一些心得
1.如何在VS code中查看函数的原代码
1)查看是否有.vscode--->c_cpp_properties.json 文件
2)如果没有,则需要点击有警告的工程路径,之后会在工程路径左上方出现一个灯泡的图案,点击灯泡图案会出现4个选项,之后选择---编辑“includePath”设置,就会出现.vscode--->c_cpp_properties.json 文件;
3)打开.vscode--->c_cpp_properties.json 文件,在includePath下添加对应的工程路径头文件
例如:添加blink例程中的gpio相关函数的定义和声明
2.如何使用ESP32的文档查看代码中的对应函数
1)下载ESP32编程指南
2)打开ESP32编程指南:API参考--->外设API--->GPIO&RTC GPIO