# Arduino Button Game

510

2

3

Published

## Introduction: Arduino Button Game

This is a LED game of two players.

Check out the video.

## 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[5]={4,5,6,7,8}; //LEDs for 1st player

int led_1[5]={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;

}

}

}

## Step 4: Rules to Play the Game

There are two buttons one for each player. Both player should press their respective buttons in order to complete switching of their five LED s. The one who turn on their all five LED s before other will be declared as winner... all LED s of winner will start blinking which will indicate the winning state...

## Recommendations

• ### Arduino Class

69,758 Enrolled

• ### Make it Move Contest

We have a be nice policy.