基于ESP32-C3的点灯-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 387|回复: 0

[分享] 基于ESP32-C3的点灯

[复制链接]
发表于 2022-9-30 08:37 | 显示全部楼层 |阅读模式
基于ESP32-C3的通过ESP-idf进行点灯



搭建好esp-idf的开发环境及VScode的开发配置之后,开始我们的点灯之旅:

LED GPIO位置引脚图:
0006.png

1、在VScode使用快捷键F1调出配置菜单
0001.png
2、选择ESP-id版本
0002.png
3、选择点灯示例
0003.png

0004.png

4、示例代码源文件blink_example_main.c
  1. /* Blink Example

  2.    This example code is in the Public Domain (or CC0 licensed, at your option.)

  3.    Unless required by applicable law or agreed to in writing, this
  4.    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5.    CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #include <stdio.h>
  8. #include "freertos/FreeRTOS.h"
  9. #include "freertos/task.h"
  10. #include "driver/gpio.h"
  11. #include "esp_log.h"
  12. #include "led_strip.h"
  13. #include "sdkconfig.h"

  14. static const char *TAG = "example";

  15. /* Use project configuration menu (idf.py menuconfig) to choose the GPIO to blink,
  16.    or you can edit the following line and set a number here.
  17. */
  18. //#define BLINK_GPIO CONFIG_BLINK_GPIO
  19. #define BLINK_GPIO 12

  20. static uint8_t s_led_state = 0;

  21. static void blink_led(void)
  22. {
  23.     /* Set the GPIO level according to the state (LOW or HIGH)*/
  24.     gpio_set_level(BLINK_GPIO, s_led_state);
  25. }

  26. static void configure_led(void)
  27. {
  28.     ESP_LOGI(TAG, "Example configured to blink GPIO LED!");
  29.     gpio_reset_pin(BLINK_GPIO);
  30.     /* Set the GPIO as a push/pull output */
  31.     gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
  32. }

  33. void app_main(void)
  34. {

  35.     /* Configure the peripheral according to the LED type */
  36.     configure_led();

  37.     while (1) {
  38.         ESP_LOGI(TAG, "Turning the LED %s!", s_led_state == true ? "ON" : "OFF");
  39.         blink_led();
  40.         /* Toggle the LED state */
  41.         s_led_state = !s_led_state;
  42.         vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS);
  43.     }
  44. }
复制代码
5、编译与烧录:
0007.png

演示视频:
https://www.bilibili.com/video/BV1FW4y1e7wP/

【基于ESP32-C3的通过ESP-idf进行点灯】 https://www.bilibili.com/video/BV1FW4y1e7wP?share_source=copy_web&amp;vd_source=6437f4c3a3ab00a4eff3cdff6295691e

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-1 05:19 , Processed in 0.075487 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表