///////////////////// Blinking and LEDs 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) gpio_get_level() function of the API
5) Create a template from gpio_config_t struct for GPIO common configuration. */
//////////////==== The configuration parameters of GPIO pad for gpio_config_t struct ====/////////////
//gpio_pin_bit_mask; /* GPIO pin: set with bit mask, each bit maps to a GPIO */
//gpio_mode_t mode; /* GPIO mode: set input/output mode */
//gpio_pullup_t pull_up_en; /* GPIO pull-up */
//gpio_pulldown_t pull_down_en; /* GPIO pull-down */
//gpio_int_type_t intr_type; /* GPIO interrupt type */
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define LED1 GPIO_NUM_2 /* Define the GPIO2 as LED1 */
#define LED2 GPIO_NUM_4 /* Define the GPIO4 as LED2 */
#define LED3 GPIO_NUM_5 /* Define the GPIO5 as LED3 */
/* Create a template from gpio_config_t struct for GPIO common configuration. */
/* Name the struct template as GPIO_Config */
gpio_config_t GPIO_Config;
void app_main(void) {
/* Configure Digital I/O for LEDs */
GPIO_Config.pin_bit_mask = (1 << LED1) | (1 << LED2) | (1 << LED3); /* set with bit mask, each bit maps to */
GPIO_Config.pull_down_en = GPIO_PULLDOWN_DISABLE; /* pull-down ENABLE/DISABLE */
GPIO_Config.pull_up_en = GPIO_PULLUP_DISABLE; /* pull-up ENABLE/DISABLE */
GPIO_Config.mode = GPIO_MODE_OUTPUT; /* GPIO output type */
GPIO_Config.intr_type = GPIO_INTR_DISABLE; /* interrupt type */
gpio_config(&GPIO_Config); /* Initialize GPIO */
while(1)
{
// turn the LEDs ON in one order
gpio_set_level(LED1, 1);
vTaskDelay(250 / portTICK_PERIOD_MS);
gpio_set_level(LED2, 1);
vTaskDelay(250 / portTICK_PERIOD_MS);
gpio_set_level(LED3, 1);
vTaskDelay(250 / portTICK_PERIOD_MS);
// turn OFF in the same order
gpio_set_level(LED1, 0);
vTaskDelay(250 / portTICK_PERIOD_MS);
gpio_set_level(LED2, 0);
vTaskDelay(250 / portTICK_PERIOD_MS);
gpio_set_level(LED3, 0);
vTaskDelay(250 / portTICK_PERIOD_MS);
}
}