rudraksh2008
Published

Connecting pushbutton with Arduino and making light patterns

It's so cool if we press a button and all the LEDs dance on our command. So let's get started!

IntermediateFull instructions provided714
Connecting pushbutton with Arduino and making light patterns

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Resistor 220 ohm
Resistor 220 ohm
×8
Resistor 10k ohm
Resistor 10k ohm
×1
5 mm LED: Red
5 mm LED: Red
×1
Male to male wires
×1
Push Button
×1

Software apps and online services

Arduino IDE

Story

Read more

Schematics

Connection of Push button with Arduino and LEDs

This connection is for example. You have to do connection as commented in the code. This code is to show you only the connection! Do It Yourself!

Code

Upload this code and see results by simply pressing the pushbutton

C/C++
I highly recommend to type this code (in short) so you can get familiar with all the commands that are used in this code!
int L1 = 3; // connect LED1 to digital pin 3
int L2 = 4; // connect LED2 to digital pin 4
int L3 = 5; // connect LED3 to digital pin 5
int L4 = 6; // connect LED4 to digital pin 6
int L5 = 7; // connect LED5 to digital pin 7
int L6 = 8; // connect LED6 to digital pin 8
int L7 = 9; // connect LED7 to digital pin 9
int L8 = 10; // connect LED8 to digital pin 10

int buttonState = 0; // Assign a button value
int buttonPin = 2; // connect Push Button to digital pin 2

int de = 50; // it's delay which is used later in patterns of LEDs

int p = 0; // It's the pattern number of LEDs

void setup() {
  pinMode(L1, OUTPUT);
  pinMode(L2, OUTPUT);
  pinMode(L3, OUTPUT);
  pinMode(L4, OUTPUT);
  pinMode(L5, OUTPUT); // Declare all LED pins as OUTPUT pins
  pinMode(L6, OUTPUT);
  pinMode(L7, OUTPUT);
  pinMode(L8, OUTPUT);

  pinMode(buttonPin, INPUT); // Declare Push Button Pin as INPUT pins
}

void loop() {
  buttonState = digitalRead(buttonPin); // Connect Push Button to Arduino
  
  if (buttonState==HIGH)

  {
    p++;              // This 'IF' condition specifies that whenever Push Button is pressed, that will do increment in pattern numbers
    delay(500);                    
  }

  if (p==1) // This is pattern number 1 and the code inside this is the pattern in which all the LEDs will glow!
  {
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 1);
     digitalWrite(L8, 1);
  }    
  

  if (p==2) // Same way pattern no.2
  {
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 1);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
  }


    if (p==3) // Pattern no.3
    {
     digitalWrite(L1, 1);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 1);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 1);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 1);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 1);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 1);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 1);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 1);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 1);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 1);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 1);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 1);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 1);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
    }

   if (p==4) // Pattern no.4
   {
     digitalWrite(L1, 1);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 1);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 1);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 1);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 1);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 1);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 1);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 1);
     digitalWrite(L7, 1);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 1);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 0);
     digitalWrite(L6, 0);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 0);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 1);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 1);
     digitalWrite(L2, 1);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 1);
     digitalWrite(L2, 1);
     digitalWrite(L1, 1);
     delay(de);
     digitalWrite(L8, 0);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 1);
     digitalWrite(L2, 1);
     digitalWrite(L1, 1);
     delay(de);
     digitalWrite(L8, 0);
     digitalWrite(L7, 0);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 1);
     digitalWrite(L2, 1);
     digitalWrite(L1, 1);
     delay(de);
     digitalWrite(L8, 0);
     digitalWrite(L7, 0);
     digitalWrite(L6, 0);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 1);
     digitalWrite(L2, 1);
     digitalWrite(L1, 1);
     delay(de);
     digitalWrite(L8, 0);
     digitalWrite(L7, 0);
     digitalWrite(L6, 0);
     digitalWrite(L5, 0);
     digitalWrite(L4, 1);
     digitalWrite(L3, 1);
     digitalWrite(L2, 1);
     digitalWrite(L1, 1);
     delay(de);
     digitalWrite(L8, 0);
     digitalWrite(L7, 0);
     digitalWrite(L6, 0);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 1);
     digitalWrite(L2, 1);
     digitalWrite(L1, 1);
     delay(de);
     digitalWrite(L8, 0);
     digitalWrite(L7, 0);
     digitalWrite(L6, 0);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 1);
     digitalWrite(L1, 1);
     delay(de);
     digitalWrite(L8, 0);
     digitalWrite(L7, 0);
     digitalWrite(L6, 0);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 1);
     delay(de);
     digitalWrite(L8, 0);
     digitalWrite(L7, 0);
     digitalWrite(L6, 0);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
   }


     if (p==5) // Pattern no.5
   {
     digitalWrite(L1, 1);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 1);
     digitalWrite(L8, 0);
     delay(de); 
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 1);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 1);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 1);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 1);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 1);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 1);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
   }

     if (p==6) // Pattern no.6
   {
     digitalWrite(L8, 1);
     digitalWrite(L7, 0);
     digitalWrite(L6, 0);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 0);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 1);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 1);
     digitalWrite(L2, 1);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 1);
     digitalWrite(L2, 1);
     digitalWrite(L1, 1);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 1);
     digitalWrite(L2, 1);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 1);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 1);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 1);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 1);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 1);
     digitalWrite(L6, 0);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 1);
     digitalWrite(L7, 0);
     digitalWrite(L6, 0);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
     digitalWrite(L8, 0);
     digitalWrite(L7, 0);
     digitalWrite(L6, 0);
     digitalWrite(L5, 0);
     digitalWrite(L4, 0);
     digitalWrite(L3, 0);
     digitalWrite(L2, 0);
     digitalWrite(L1, 0);
     delay(de);
   }

     if (p==7) // Pattern no.7
   {
     digitalWrite(L1, 1);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 1);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 1);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 1);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 1);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 1);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 1);
     digitalWrite(L5, 1);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 1);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 1);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 0);
     digitalWrite(L2, 1);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 1);
     digitalWrite(L8, 0);
     delay(de);
     digitalWrite(L1, 1);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 1);
     delay(de);
   }

       if (p==8) // Pattern no.8. In this pattern, all the LEDs are turned OFF!
   {
     digitalWrite(L1, 0);
     digitalWrite(L2, 0);
     digitalWrite(L3, 0);
     digitalWrite(L4, 0);
     digitalWrite(L5, 0);
     digitalWrite(L6, 0);
     digitalWrite(L7, 0);
     digitalWrite(L8, 0);
     p=0; // This is the command to bring the pattern no. again to '0' and the patterns will restart from 1st pattern
   }


   
}              

                      // Hope that you understood the code!
                      // Meet in the next project!
                      // BYE!!
   

Credits

rudraksh2008

rudraksh2008

4 projects • 1 follower

Comments