#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
/*
https://github.com/Codaerus/C-PARA-EMBEBIDOS-CON-ESP32/blob/main/CLASE2/doc.h
*/
#define LED_GPIO_PIN GPIO_NUM_2
#define BUTTON_GPIO_PIN GPIO_NUM_4
void app_main() {
//Configurar la direccion o modo(como Salida)
gpio_set_direction(LED_GPIO_PIN, GPIO_MODE_OUTPUT);
//Configurar la direccion o modo(como Entrada y RPU Pull Up)
gpio_set_direction(BUTTON_GPIO_PIN, GPIO_MODE_INPUT);
gpio_set_pull_mode(BUTTON_GPIO_PIN, GPIO_PULLUP_ONLY);
while(1){
int buttonState=gpio_get_level(BUTTON_GPIO_PIN);
if(buttonState==0){ //Pulsador presionado (por ser Pull Up)
gpio_set_level(LED_GPIO_PIN, 1); //Encender LED
}else{
gpio_set_level(LED_GPIO_PIN, 0); //Apagar LED
}
}
}