# Arduino Button Game

993

2

3

This is a LED game of two players.

Check out the video.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Parts List

1x Arduino nano

2x Push button

12x 220 Ohms resistor

1x Breadboard or stripboard, as you prefer

1x USB Cable

and connecting wires.

## Step 2: Circuit Diagram

This is very simple circuit.

## Step 3: Code

/*

* Arduino Button Game

*

* B.Tech 3rd sem

* Student at Lovely Professional University

* */

int led={4,5,6,7,8}; //LEDs for 1st player

int led_1={9,10,11,12,13};//LEDs for 2nd player

int i=0;

int j=0;

int button_1=0;//Button input for player 1

int button_2=0;//Button input for player 2

void setup() {

//INPUT Pin mode

for(int thispin=4;thispin<14;thispin++)

{

pinMode(thispin,OUTPUT);

}

//OUTPUT Pin mode

pinMode(2,INPUT);

pinMode(3,INPUT);

}

void loop()

{

if(button_1==HIGH) {

do

{

digitalWrite(led[i],HIGH);

if(i<4)

{

i++;

}

else if(i==4)

{

for(int thispin=4;thispin<9;thispin++)

{

digitalWrite(thispin,LOW);

}

delay(200);

for(int thispin=4;thispin<9;thispin++)

{

digitalWrite(thispin,HIGH);

}

delay(200);

for(int thispin=4;thispin<9;thispin++)

{

digitalWrite(thispin,LOW);

}

delay(200);

for(int thispin=4;thispin<9;thispin++)

{

digitalWrite(thispin,HIGH);

}

delay(200);

for(int thispin=4;thispin<14;thispin++)

{

digitalWrite(thispin,LOW);

}

j=0;

i=0;

}

else

{

i=0;

}

}

if(button_2==HIGH)

{

do

{

digitalWrite(led_1[j],HIGH);

if(j<4)

{

j++;

}

else if(j==4)

{

for(int thispin=9;thispin<14;thispin++)

{

digitalWrite(thispin,LOW);

}

delay(200);

for(int thispin=9;thispin<14;thispin++)

{

digitalWrite(thispin,HIGH);

}

delay(200);

for(int thispin=9;thispin<14;thispin++)

{

digitalWrite(thispin,LOW);

}

delay(200);

for(int thispin=9;thispin<14;thispin++)

{

digitalWrite(thispin,HIGH);

}

delay(200);

for(int thispin=4;thispin<14;thispin++)

{

digitalWrite(thispin,LOW);

}

i=0;

j=0;

}

else

{

j=0;

}

}

}