
Encender un LED con Espidf
Ahora que tenemos instalado Espidf vamos a Encender un LED con Espidf, creando un nuevo proyecto basado en una plantilla que tiene la función de encender y apagar un led cada segundo siguiendo estos pasos:
Crear un proyecto
Hacemos click en New -> Espressif IDF Project

Colocamos el nombre del proyecto en este caso prueba y click en siguiente

Click en el check “Create a project using one of the templates” seleccionamos blink y click en Finish

Desplegamos blink, desplegamos main y doble click en blink_example_main.c y cambiamos CONFIG_BLINK_GPIO por numero 2

Damos click en Build y despues en OK

Buscar el puerto de ESP32
Abrimos el buscador de aplicación y escribimos “administrador de dispositivos” y damos enter

Buscamos en la categoría Puertos (COM) el nuevo puerto que se creó. Si no lo ubicamos, desconectamos y conectamos la cámara espía.

Subimos el código
Click en el engrane, colocamos un nombre, seleccionamos un target y seleccioanamos el puerto en m caso el 09

Click en Run y esperamos que suba el proyecto

Circuito


Código para Encender un LED con Espidf
/* Encender un LED con Espidf Blink Example This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #include <stdio.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/gpio.h" #include "esp_log.h" #include "led_strip.h" #include "sdkconfig.h" static const char *TAG = "example"; /* Use project configuration menu (idf.py menuconfig) to choose the GPIO to blink, or you can edit the following line and set a number here. */ #define BLINK_GPIO 2 static uint8_t s_led_state = 0; #ifdef CONFIG_BLINK_LED_RMT static led_strip_t *pStrip_a; static void blink_led(void) { /* If the addressable LED is enabled */ if (s_led_state) { /* Set the LED pixel using RGB from 0 (0%) to 255 (100%) for each color */ pStrip_a->set_pixel(pStrip_a, 0, 16, 16, 16); /* Refresh the strip to send data */ pStrip_a->refresh(pStrip_a, 100); } else { /* Set all LED off to clear all pixels */ pStrip_a->clear(pStrip_a, 50); } } static void configure_led(void) { ESP_LOGI(TAG, "Example configured to blink addressable LED!"); /* LED strip initialization with the GPIO and pixels number*/ pStrip_a = led_strip_init(CONFIG_BLINK_LED_RMT_CHANNEL, BLINK_GPIO, 1); /* Set all LED off to clear all pixels */ pStrip_a->clear(pStrip_a, 50); } #elif CONFIG_BLINK_LED_GPIO static void blink_led(void) { /* Set the GPIO level according to the state (LOW or HIGH)*/ gpio_set_level(BLINK_GPIO, s_led_state); } static void configure_led(void) { ESP_LOGI(TAG, "Example configured to blink GPIO LED!"); gpio_reset_pin(BLINK_GPIO); /* Set the GPIO as a push/pull output */ gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); } #endif void app_main(void) { /* Configure the peripheral according to the LED type */ configure_led(); while (1) { ESP_LOGI(TAG, "Turning the LED %s!", s_led_state == true ? "ON" : "OFF"); blink_led(); /* Toggle the LED state */ s_led_state = !s_led_state; vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS); } }
Lista de reproducción en YouTube de ESP32: https://www.youtube.com/watch?v=uUWOFP8V1WY&list=PLCTD_CpMeEKRDz5ISmZHaVR-4a64rzOKC&ab_channel=ProgramadorNovato
🎦 Este curso: https://www.youtube.com/watch?v=VuJkqL2Ys3Y&list=PLCTD_CpMeEKTvjzabAvLGHakg-ql6t0q6&ab_channel=ProgramadorNovato
🎦 Curso de Arduino: https://www.youtube.com/watch?v=oGinJt9aALc&list=PLCTD_CpMeEKSqw3Nh7rA9aXUAzbPIPkdv&ab_channel=ProgramadorNovato
🎦 [CURSO] C++ DE 0 A HEROE: https://www.youtube.com/watch?v=APN8aCyPvww&list=PLCTD_CpMeEKTofxs7iottRxJ5YPM7BOcc