Working with GPIO & Buttons using ESP32

Hi community! Today's project is gonna be about how to use the GPIO Functions & Buttons in our ESP32 microcontroller!

Hi Community!

In this project we will see the step by step of our code and its operation, we have to achieve using a button and 2 LEDs (Red and Green), turn off the LED red when pressing the button and when you stop welding return to the state in which the red LED is lit, this codewill be achieved thanks to previous theoretical concepts, where we touch on topics of GPIO and using the PlatformIO platform.

Step 1

First we make the circuit for our project:

Step 2

First we will do the procedure of creating the new project by the platform PlatformIO. After creating this project, we remember to put the speed of the card in the file configuration, which is about 115200.

Step 3

We start by creating the code, applying the necessary libraries so that our code can work:

Step 4

We define our input and output of the circuit, in the case of the input it would be the 3 LEDs of different colors:

Step 5

The function is created for the Inputs and Outputs to work:

Step 6

Then the I/O function we created before, in our code or function will be called main where the logic goes:

Step 7

Then the logic of our circuit will begin, in which it is needed to turn on mainly the Red LED, after this when we press the button, the state of the Red LED changes to 0 and green LED changes to 1 and turns on. when you stop pressing the states return to their main states, the red LED on and the green LED off:

Step 8

Next, we will see test images where you can see that it was achieved successfully the experience: