Break The Targets

Break the Targets is a competive action shooting game in which you are given a blaster–target breaker, nerf gun–and tasked with hitting all six targets on the board before the timelimit runs out.

Description:

Load your gun.

Take aim.

FIRE.

You have One Minute to hit all the targets before the timer runs out.

Functionality:

The game utilizes 6 light sensors, 2 seperate arduinos, and 24 different individually wired leds.

One ardunio governs the targets. It turns on all the target lights at the start and then turns off each target when the corresponding light sensor is hit.

The other ardunio governs the lights around the border of the game. These lights blink and dance, counting down the 60 secs the player has to break all the targets. When time is up they turn off and a buzzer sounds.

There is a reset button for each arduino.

Circuit diagram:

Coming soon.

Code:

Arduino #1

int button = 11;  //define pin for button

int buzzer = 9; //deifnie buzzer

 

int LDR0 = 0; //define pin for the Photo resistor1

int LDR1 = 1; //define pin for the Photo resistor2

int LDR2 = 2; //define pin for the Photo resistor3

int LDR3 = 3; //define pin for the Photo resistor4

int LDR4 = 4; //define pin for the Photo resistor5

int LDR5 = 5; //define pin for the Photo resistor6

 

int bam = 20; //threshold

 

int LED2 = 2; //define pin for LED 1

int LED3 = 3; //define pin for LED 2

int LED4 = 4; //define pin for LED 3

int LED5 = 5; //define pin for LED 4

int LED6 = 6; //define pin for LED 5

int LED7 = 7; //define pin for LED 6

                                           

int t1dead = 0;

int t2dead = 0;

int t3dead = 0;

int t4dead = 0;

int t5dead = 0;

int t6dead = 0;

                                                                      

int val0 = 0; 

int val1 = 0;

int val2 = 0;

int val3 = 0; 

int val4 = 0;

int val5 = 0;

 

int input = 0;                    // variable for reading the pin status

 

void setup() {

 Serial.begin(9600); 

  pinMode(button, INPUT);     // declare pushbutton as input

 

}

 

void loop(){

 

Serial.println(val0); //Write the value of the photoresistor to the serial monitor.

 

val0 = analogRead(LDR0);

val1 = analogRead(LDR1);

val2 = analogRead(LDR2);

val3 = analogRead(LDR3);

val4 = analogRead(LDR4);

val5 = analogRead(LDR5);

 

analogWrite(LED2, analogRead(LDR0)/4); //send the value to the status. Depending on value of resistor

analogWrite(LED3, analogRead(LDR1)/4); //send the value to the status. Depending on value of resistor

analogWrite(LED4, analogRead(LDR2)/4); //send the value to the status. Depending on value of resistor

analogWrite(LED5, analogRead(LDR3)/4); //send the value to the status. Depending on value of resistor

analogWrite(LED6, analogRead(LDR4)/4); //send the value to the status. Depending on value of resistor

analogWrite(LED7, analogRead(LDR5)/4); //send the value to the status. Depending on value of resistor

 

delay(10); //short delay for faster response to light.

 

if (t1dead == 0) { // if targets not dead make it bright

    digitalWrite(LED2, HIGH);

  }

  

if (t2dead == 0) { // if targets not dead make it bright

    digitalWrite(LED3, HIGH);

  }

  

if (t3dead == 0) { // if targets not dead make it bright

    digitalWrite(LED4, HIGH);

  }

  

if (t4dead == 0) { // if targets not dead make it bright

    digitalWrite(LED5, HIGH);

  }

  

if (t5dead == 0) { // if targets not dead make it bright

    digitalWrite(LED6, 500);

  }

  

if (t6dead == 0) { // if targets not dead make it bright

    digitalWrite(LED7, 500);

  }

  

if (val0 < bam) { // if dark turn on LED2

    digitalWrite(LED2, 0);

    t1dead = 1;

    digitalWrite(buzzer, HIGH);

    delay(500);

  }

  

if (val1 < bam) { // if dark turn on LED2

    digitalWrite(LED2, 0);

    t2dead = 1;

    digitalWrite(buzzer, HIGH);

    delay(500);

  }

  

if (val2 < bam) { // if dark turn on LED2

    digitalWrite(LED2, 0);

    t3dead = 1;

    digitalWrite(buzzer, HIGH);

    delay(500);

  }

  

if (val3 < bam) { // if dark turn on LED2

    digitalWrite(LED2, 0);

    t4dead = 1;

    digitalWrite(buzzer, HIGH);

    delay(500);

  }

  

if (val4 < bam) { // if dark turn on LED2

    digitalWrite(LED2, 0);

    t5dead = 1;

    digitalWrite(buzzer, HIGH);

    delay(500);

  }

  

if (val5 < bam) { // if dark turn on LED2

    digitalWrite(LED2, 0);

    digitalWrite(buzzer, HIGH);

    delay(500);

  }

  

 

  input = digitalRead(button);  // read BUTTON INPUT value

  

    if (input == HIGH) {   // check if the input is LOW (this means TIMER RESET BUTTON IS pushed)

        t1dead = 0;

        t2dead = 0;

        t3dead = 0;

        t4dead = 0;

        t5dead = 0;

        t6dead = 0;

        

      }  

  }

   

Arduino #2

 

int button = 11;  //define pin for button

 

int LED1 = 2;

int LED2 = 3;

int LED3 = 4;

int LED4 = 5;

int LED5 = 6;

int LED6 = 7;

 

int counter = 600 ;

int timelimit = 60; // value in seconds (total timer time 5 min)

int warningtime = 10; // value in seconds (warning issued at 30 seconds)

 

int input = 0;                    // variable for reading the pin status

 

void setup() {

  Serial.begin(9600); 

  pinMode(button, INPUT);     // declare pushbutton as input

 

}

 

void loop(){

 

Serial.println(counter);

 

  input = digitalRead(button);  // read BUTTON INPUT value

    if (input == HIGH) {  

 

        counter = timelimit*10; // set the counter to the time limit

 

                  digitalWrite(LED1, HIGH); // LED ON

                  digitalWrite(LED2, HIGH); // LED ON

                  digitalWrite(LED3, HIGH); // LED ON

                  digitalWrite(LED4, HIGH); // LED ON

                  digitalWrite(LED5, HIGH); // LED ON

                  digitalWrite(LED6, HIGH); // LED ON

       /*  delay (1000) ;

                  digitalWrite(LED1, LOW); // LED OFF

                  digitalWrite(LED2, LOW); // LED OFF

                  digitalWrite(LED3, LOW); // LED OFF

                  digitalWrite(LED4, LOW); // LED OFF

                  digitalWrite(LED5, LOW); // LED OFF

                  digitalWrite(LED6, LOW); // LED OFF

                  */

      } 

    else { //RESET BUTTON IS NOT PUSHED SO TIMER STARTS OVER

        if( counter > 1){ //TIMER IS NOT YET EXPIRED

              counter– ;  //decrease counter by 1

              if (counter <= warningtime*10) { // IN THE WARNING STAGE FLASH ALOT

                  digitalWrite(LED1, HIGH); // LED ON

                  delay (150);

                  digitalWrite(LED2, HIGH); // LED ON

                  delay (20);

                  digitalWrite(LED3, HIGH); // LED ON

                  delay (150);

                  digitalWrite(LED4, HIGH); // LED ON

                  delay (20);

                  digitalWrite(LED5, HIGH); // LED ON

                  delay (150);

                  digitalWrite(LED6, HIGH); // LED ON

                  delay (20);

                  digitalWrite(LED1, LOW); // LED OFF

                  delay (150);                  

                  digitalWrite(LED2, LOW); // LED OFF

                  delay (20);

                  digitalWrite(LED3, LOW); // LED OFF

                  delay (150);

                  digitalWrite(LED4, LOW); // LED OFF

                  delay (20);

                  digitalWrite(LED5, LOW); // LED OFF

                  delay (150);

                  digitalWrite(LED6, LOW); // LED OFF

                  delay(40);

              }

              else { // NORMAL COUNTDOWN MODE

                  digitalWrite(LED1, HIGH); // LED ON

                  delay (80);                  

                  digitalWrite(LED2, HIGH); // LED ON

                  delay (15);                  

                  digitalWrite(LED3, HIGH); // LED ON

                  delay (80);                  

                  digitalWrite(LED4, HIGH); // LED ON

                  delay (15);                  

                  digitalWrite(LED5, HIGH); // LED ON

                  delay (80);                  

                  digitalWrite(LED6, HIGH); // LED ON

                  delay (15);

                  digitalWrite(LED1, LOW); // LED OFF

                  delay (80);                  

                  digitalWrite(LED2, LOW); // LED OFF

                  delay (15);                  

                  digitalWrite(LED3, LOW); // LED OFF

                  delay (80);                  

                  digitalWrite(LED4, LOW); // LED OFF

                  delay (15);                  

                  digitalWrite(LED5, LOW); // LED OFF

                  delay (80);                  

                  digitalWrite(LED6, LOW); // LED OFF

                  delay(20);

              } 

         }

         if (counter == 1) { // TIMER DONE - PLAY TIMER DONE BEEPS

           for (int i = 0; i < 5; i++) {

                  digitalWrite(LED1, HIGH); // LED ON

                  digitalWrite(LED2, HIGH); // LED ON

                  digitalWrite(LED3, HIGH); // LED ON

                  digitalWrite(LED4, HIGH); // LED ON

                  digitalWrite(LED5, HIGH); // LED ON

                  digitalWrite(LED6, HIGH); // LED ON

/*             delay (200);

                  digitalWrite(LED1, LOW); // LED OFF

                  digitalWrite(LED2, LOW); // LED OFF

                  digitalWrite(LED3, LOW); // LED OFF

                  digitalWrite(LED4, LOW); // LED OFF

                  digitalWrite(LED5, LOW); // LED OFF

                  digitalWrite(LED6, LOW); // LED OFF

             delay(200);

*/             

           }

           counter = 0;

         }

         if (counter == 0) {          // TIMER IS WAITING FOR ANOTHER RESTART BUTTON PRESS

                  digitalWrite(LED1, LOW); // LED OFF

                  digitalWrite(LED2, LOW); // LED OFF

                  digitalWrite(LED3, LOW); // LED OFF

                  digitalWrite(LED4, LOW); // LED OFF

                  digitalWrite(LED5, LOW); // LED OFF

                  digitalWrite(LED6, LOW); // LED OFF

         }

       }

  }