////////////////////////////////////////////////////////////////////////////////////////////////
// Blinking an LED using ESP IDF with ESP32
// 1) Understanding the gpio_reset_pin() function of the API
// 2) Understanding the gpio_set_direction() function of the API
// 3) Understanding the gpio_set_level() function of the API
// 4) Understanding the gpio_get_level() function of the API
////////////////////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define LED GPIO_NUM_2 // define the LED Pin
void app_main(void)
{
// Configure the peripheral according to the LED type */
gpio_reset_pin(LED); // First reset the gpio to default state
gpio_set_direction(LED, GPIO_MODE_OUTPUT); // Configure the GPIO direction as output_only
// Get into the loop
while (1) {
gpio_set_level(LED, true); // Set the GPIO output level to HIGH
if(gpio_get_level(LED)==1){
printf("ON\n");
}
vTaskDelay(250 / portTICK_PERIOD_MS); // delay
gpio_set_level(LED, false); // Set the GPIO output level to LOW
if(gpio_get_level(LED)==0){
printf("OFF\n");
}
vTaskDelay(250 / portTICK_PERIOD_MS); // delay
}
}