Blinking multiple LEDs using switch case
Here, we will discuss a project to turn ON one led from multiple LEDs based on the value in the variable.
Let's start with the project.
The components required for the project are listed below:
We can use any color LED as per our choice.
We will connect the four LEDs to pins 12, 11, 8, and 6 of the Arduino board. The resistors of 220 Ohm are connected in series with the LEDs.
The switch statement will compare the declared value of a variable with statements in other cases. The code associated with the matching case will run.
We will also change or rearrange the LEDs connected to the specified pin number on the board.
Structure of the project
The structure clearly shows the UNO board's pinout, and the four LEDs with resistors in series are connected to the board.
It is shown below:
The connection of the above project is discussed below:
Consider the below code:
In the above code, the specified value of variable matches with case 3. Hence, the LED connected to pin number 11 will light up.
We will show the connection using the Simulator because the connections become clearer and more precise.
We can make the same connection using the hardware devices.
The LED connected to the PIN 11 will light up, as shown below: