2.2 GPIO - LED Multi
Last updated
Last updated
In last tutorial, we successfully light a led with PlatformIO IDE. So this time let’s expand this example to multiple LEDs and do some further programming.
Here’s a list of the parts to you need to build the circuit:
ESP32-S3-N16R8 x 1
5 mm LED x 5
330 - 1000 Ohm resistor
Breadboard
Jumper wires
At this example, we control five LEDs here is the diagram. The positive pole of each LED is connected to a GPIO pin of the development board and a resistor is connected in series, and the negative pole is connected to GND.
While we can use only one resistor to realize this. Following is the diagram, and you can use each one of them and the code would be the same.
As we are going to use multiple GPIO pins, it is best to put all the GPIO pins in an array and then iterate through the array.
We can also update the program. For example, before, the status of the running lights was changed sequentially. Now, we can change it to make the lights running back and forth.
The effect of making the LED shift is achieved like this. Every time I light up this LED, the state of the previous LED is changed to a low level at the same time, and when the index value is 0, the state of the last LED is changed to a low level.
At this example, we use for loop to realize different effects of LEDs.
Make sure you have it installed PlatformIO extension in your VScode. ()
If you have any questions for setting up the IDE or uploading the code, please check the previous tutorial: