Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will be creating a game in C++ for your Arduino called \"Time bomb.\" The ga

ID: 3875954 • Letter: Y

Question

You will be creating a game in C++ for your Arduino called "Time bomb." The game randomly generates a disarming code and gives the player a 25-second time limit countdown to 0. The countdown is displayed on the 8-segment display from 0025 down to 0000. The disarming code is input by the player using the three pushbuttons (A1, A2, and A3). The disarming code is some random combination of these buttons. For example, if I generate a code of 0, 2, 2, 1, then I must press the left button, the right button twice, and then the middle button to disarm the bomb. If I do not press the correct button, the player must enter the code starting from the beginning. Every time the user presses the correct button, you will light an LED from bottom to top. If the user presses the wrong button, then clear all LEDs so the user can start over again. The player wins by lighting all four LEDs, meaning they inputted the correct 4-button sequence. If the user presses the correct four button sequence, display dashes (----) for 3 seconds, and then start the game from the beginning. If the user does not press the correct four button sequence and the time limit counts down to 0, then you will display all zeroes (0000) for 3 seconds. During these 3 seconds, sound the buzzer (pin 3) to simulate a "time bomb" sound. After the 3 seconds, restart the game with a new, random, 4-button disarming code and 25-second time limit.

Explanation / Answer

Here is the Arduino disarming code for the specify Time bomb game .

long preemills;

int counting = 0025;

int code[4]= [0,2,2,1];

void setup(){

Serial.begin(9600); // serial port 9600 bps set data rate

pinMode(13,OUTPUT);

digitalWrite(13, HIGH);

pinMode(3, OUTPUT); //buzzer Pin for beep sound

beep(50);

beep(50);

delay(3000);// 3 second delay

  

}

}

void loop(){  

unsigned long noemills = millis();

Serial.begin(9600);

Serial.println("Time bomb starting....");

preemills = millis();  

Serial.println(counting);// counting print

delay(3000);

char input = keypad.getKey();//get enter input

if (input == '#') {

flag=0;

if (flag==0)

{

inputArray[b] = input;

b++;

inputArray[b] = '';

if (inputArray[0] == Code[0] && inputArray[1] != code[1] ) // only 1st character match

{

digitalWrite(13, HIGH);

flag=0;

break;

}

if (inputArray[0] == code[0] && inputArray[1] == code[1] && inputArray[2] != code[2])//only first two character match

{

digitalWrite(13, HIGH);

digitalWrite(13, HIGH);

flag=0;

break;

}

if (inputArray[0] == code[0] && inputArray[1] == code[1] && inputArray[2] == code[2] && inputArray[3] != code[3] ) //only 1st three character match

{

digitalWrite(13, HIGH);

digitalWrite(13, HIGH);

digitalWrite(13, HIGH);

flag=0;

break;

}

if (inputArray[0] == code[0] && inputArray[1] == code[1] && inputArray[2] == code[2] && inputArray[3] == code[3] ) // all four character match

{

digitalWrite(13, HIGH);

digitalWrite(13, HIGH);

digitalWrite(13, HIGH);

digitalWrite(13, HIGH);

flag=0;

lcd.clear();

lcd.setCursor(0,0);

lcd.print("----------------------------------"); // display text

delay(3000); // 3000s

lcd.clear();

}

}

}

}

if(noemills - preemills >= 3000){

counting -= 1;

Serial.println(counting);

preemills += 3000;

}

  

if(counting == 0){

Serial.println("00000000000000000000000000000");

while(1);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote