1.4 Coding and Working of the project

Coding :

Steps to do coding in Arduino IDE

1. Open Arduino IDE from the desktop. You will be see the following page when you will open Arduino IDE:

2. Now , as mentioned before we will glow the 5 LEDs in 9 different patterns. So, we have to write a code to glow the leds in 9 different patterns.

3. First we will write, void setup ( ) function, which describe the status of the pin (we are using) so we use the pinMode function to change its status.

Expression :

void setup() {

pinMode(2, OUTPUT);

pinMode(3, OUTPUT);

pinMode(5, OUTPUT);

pinMode(6, OUTPUT);

pinMode(7, OUTPUT);

}

4. Then, in void loop() function, we write the main code and it run over and over again. We have to use the digitalWrite function to On and Off LED and use delay function to keep LED On and Off for some seconds.

Note : Lines mentioned in the “// ” are the comments. These comments are written for the explanation of program to programmer.

Pattern1: In the this lighting pattern, all the Led’s will first glow together and after some delay, all the Led’s will switch-off together.

Expression :

//Pattern 01
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
delay(300);

digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
delay(300);

Pattern2: In this lighting pattern, the Led’s are switched ON one after the other (from left to right) and then switched OFF one after the other  from left to right). A delay of 400 milliseconds is used when illuminating each LED and a delay of 300 milliseconds is used when switching them OFF. 

Expression :

digitalWrite(2, HIGH);
delay(400);
digitalWrite(3, HIGH);
delay(400);
digitalWrite(4, HIGH);
delay(400);
digitalWrite(5, HIGH);
delay(400);
digitalWrite(6, HIGH);
delay(400);

digitalWrite(2, LOW);
delay(300);
digitalWrite(3, LOW);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(6, LOW);
delay(300);

Pattern3: In this lighting pattern, the LEDs are switched ON one after the other (from right to left) and then switched OFF one after the other (from right to left).A delay of 400 milliseconds is used when illuminating each LED and a delay of 300 milliseconds is used when switching them OFF. 

Expression :

digitalWrite(6, HIGH);
delay(400);
digitalWrite(5, HIGH);
delay(400);
digitalWrite(4, HIGH);
delay(400);
digitalWrite(3, HIGH);
delay(400);
digitalWrite(2, HIGH);
delay(400);

digitalWrite(6, LOW);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(3, LOW);
delay(300);
digitalWrite(2, LOW);
delay(300);

Pattern4: In this lighting pattern, the odd LEDs are switched ON while the even LEDs are switched OFF. Then, the even LEDs are switched ON and the odd LEDs are switched OFF.

Pattern5: In this lighting pattern, the LEDs are switched ON one after the other (from left to right) and then they are switched OFF one after the other (from right to left).A delay of 400 milliseconds is used when illuminating each LED and a delay of 300 milliseconds is used when switching them OFF. 

Pattern6: In this lighting pattern, the LEDs are switched ON one after the other (from right to left) and then they are switched OFF one after the other (from left to right).A delay of 400 milliseconds is used when illuminating each LED and a delay of 300 milliseconds is used when switching them OFF. 

Pattern7: In this lighting pattern, tone LED from both sides is switched ON one after the other so that it slowly illuminates toward the center of the light rope. Next, it is switched OFF on both sides, fading to the center of the light rope. A delay of 400 milliseconds is used when illuminating each LED and a delay of 300 milliseconds is used when switching them OFF. 

Pattern8: In this lighting pattern, all the LEDs are blinked together.

Pattern9: In this lighting pattern, the LEDs are switched ON from the center and then toward both ends. Once the light rope is fully illuminated, the LEDs are switched OFF from the center toward both ends, simultaneously fading from the left and right sides. A delay of 100 milliseconds is used in both the sequence 

Complete Code:

void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop() {

//Pattern 01
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
delay(300);

digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
delay(300);

//Pattern 02

digitalWrite(2, HIGH);
delay(400);
digitalWrite(3, HIGH);
delay(400);
digitalWrite(4, HIGH);
delay(400);
digitalWrite(5, HIGH);
delay(400);
digitalWrite(6, HIGH);
delay(400);

digitalWrite(2, LOW);
delay(300);
digitalWrite(3, LOW);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(6, LOW);
delay(300);

//Pattern 03

digitalWrite(6, HIGH);
delay(400);
digitalWrite(5, HIGH);
delay(400);
digitalWrite(4, HIGH);
delay(400);
digitalWrite(3, HIGH);
delay(400);
digitalWrite(2, HIGH);
delay(400);

digitalWrite(6, LOW);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(3, LOW);
delay(300);
digitalWrite(2, LOW);
delay(300);

//Pattern 04

digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
delay(300);

digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
digitalWrite(3, LOW);
digitalWrite(2, HIGH);
delay(300);

//Pattern 05
digitalWrite(6, HIGH);
delay(200);
digitalWrite(5, HIGH);
delay(200);
digitalWrite(4, HIGH);
delay(200);
digitalWrite(3, HIGH);
delay(200);
digitalWrite(2, HIGH);
delay(200);

digitalWrite(2, LOW);
delay(300);
digitalWrite(3, LOW);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(6, LOW);
delay(300);

//Pattern 06
digitalWrite(2, HIGH);
delay(200);
digitalWrite(3, HIGH);
delay(200);
digitalWrite(4, HIGH);
delay(200);
digitalWrite(5, HIGH);
delay(200);
digitalWrite(6, HIGH);
delay(200);

digitalWrite(6, LOW);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(3, LOW);
delay(300);
digitalWrite(2, LOW);
delay(300);

//Pattern 07
digitalWrite(4, LOW);
delay(100);
digitalWrite(6, HIGH);
digitalWrite(2, HIGH);
delay(100);
digitalWrite(5, HIGH);
digitalWrite(3, HIGH);
delay(100);

digitalWrite(6, LOW);
digitalWrite(2, LOW);
delay(100);
digitalWrite(5, LOW);
digitalWrite(3, LOW);
delay(100);

//Pattern 08

digitalWrite(6, HIGH);
delay(300);
digitalWrite(5, HIGH);
delay(300);
digitalWrite(4, HIGH);
delay(300);
digitalWrite(3, HIGH);
delay(300);
digitalWrite(2, HIGH);
delay(300);

digitalWrite(6, LOW);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(3,LOW);
delay(300);
digitalWrite(2, LOW);
delay(300);

//Pattern 09
digitalWrite(4, HIGH);
delay(100);
digitalWrite(3, HIGH);
digitalWrite(5, HIGH);
delay(100);
digitalWrite(2, HIGH);
digitalWrite(6, HIGH);
delay(100);

digitalWrite(4, LOW);
delay(100);
digitalWrite(3, LOW);
digitalWrite(5, LOW);
delay(100);
digitalWrite(2, LOW);
digitalWrite(6, LOW);
delay(100);
}