/*
/////////////////////////////// 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) Understanding the gpio_get_level() function of the API
5) gpio_config_t Create a template from gpio_config_t struct for GPIO common configuration.
*/
///////////======The configuration parameters of GPIO pad for gpio_config_t strut=====///////////////
// uint64_t 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. */
gpio_config_t GPIO_Config; //Name the struct template as 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 a GPIO */
GPIO_Config.pull_down_en = GPIO_PULLDOWN_DISABLE; /* pull-down ENABLE/DISABLE */
GPIO_Config.pull_up_en = GPIO_PULLUP_DISABLE; /* pull-up ENABELE/DISABLE */
GPIO_Config.mode = GPIO_MODE_OUTPUT; /* set input/output mode */
GPIO_Config.intr_type = GPIO_INTR_DISABLE; /* interrupt type */
/* Pass the configuration parameters of GPIO pad for gpio_config function */
gpio_config(&GPIO_Config);
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 a 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);
}
}