Experiment 3 : LED Chasing Effect
Description :
In this experiment we create a program to simulate LED chasing effect
Components Used :
- LED Green x 2
- LED Yellow x 2
- LED Red x 2
- Arduino board
- 220Ω resistor x 6
- Breadboard
- USB cable
- Breadboard jumper wires
Circuit :
Connections are made according to the Circuit given
Code :
#define BASE 2 //define pin 2 as I/O for first LED
#define NUM 6 // number of LEDs
void setup()
{
for(int i = BASE;i < BASE + NUM;i++)
{
pinMode(i, OUTPUT); //set I/O pins as Output
}
}
void loop()
{
for(int i = BASE;i < BASE + NUM;i++)
{
digitalWrite(i, LOW); //turn off LEDs 1 by 1
delay(200); //wait for 0.2 second
}
for(int i = BASE;i < BASE + NUM;i++)
{
digitalWrite(i, HIGH); //turn on LEDs 1 by 1
delay(200); //wait for 0.2 second
}
}
Video :
The output of this experiment would be like this :