Here is the whole code.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); //Set the LCD address to 0x27 for a 16 chars and 2 line display.
int LED0 = 22; //status light, ready (blue)
int LED1 = 23; //incorrect answer (red)
int LED2 = 24; //correct answer (green)
int button_pin = 25; //start game button
int button_a = 26; //answer choice A
int button_b = 27; //answer choice B
int button_c = 28; //answer choice C
int button_d = 29; //answer choice D
int Score = 0;
void setup() {
pinMode(LED0, OUTPUT); //Define LED0 as an OUTPUT.
pinMode(LED1, OUTPUT); //Define LED1 as an OUTPUT.
pinMode(LED2, OUTPUT); //Define LED2 as an OUTPUT.
pinMode(button_pin, INPUT_PULLUP); //Define button_pin as an INPUT_PULLUP.
pinMode(button_a, INPUT_PULLUP); //Define button_a as an INPUT_PULLUP.
pinMode(button_b, INPUT_PULLUP); //Define button_b as an INPUT_PULLUP.
pinMode(button_c, INPUT_PULLUP); //Define button_c as an INPUT_PULLUP.
pinMode(button_d, INPUT_PULLUP); //Define button_d as an INPUT_PULLUP.
digitalWrite(LED1, HIGH); //Show that the game is not ready to be started.
lcd.init(); //Initialize the lcd display.
lcd.init();
lcd.backlight(); //Print a startup message on the LCD.
lcd.setCursor(0, 0);
lcd.print(F("--------------------"));
lcd.setCursor(6, 1);
lcd.print("GEEEKPI");
lcd.setCursor(1, 2);
lcd.print("Arduino IIC Screen");
lcd.setCursor(0, 3);
lcd.print(F("--------------------"));
delay(3000);
lcd.clear(); //Clear the LCD startup message.
delay(1000);
digitalWrite(LED1, LOW); //The game is ready to be started.
digitalWrite(LED2, HIGH); //Show that the system is ready to be started.
lcd.setCursor(0, 0);
lcd.print("To start, press the"); //Tell the player how to start the game "To start, press the start button."
lcd.setCursor(0, 1);
lcd.print("start button.");
}
void loop() {
if (digitalRead(button_pin) == LOW) { //Wait for the player to press start.
Score = 0; //Reset the score variable.
lcd.clear();
digitalWrite(LED2, LOW);
delay(1000);
digitalWrite(LED0, HIGH); //Turn on the 'system ready' status light.
delay(1000);
lcd.setCursor(0, 0);
lcd.print("THE GAME WILL START"); //Tell the player "THE GAME WILL START SOON..."
lcd.setCursor(0, 1);
lcd.print("SOON...");
delay(4000);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("To submit an answer,"); //Tell the player "To submit an answer, press the button that represents your answer choice."
lcd.setCursor(0, 1);
lcd.print("press the button");
lcd.setCursor(0, 2);
lcd.print("that represents your");
lcd.setCursor(0, 3);
lcd.print("answer choice.");
delay(5500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("To skip a question,"); //Tell the player "To skip a question, press or hold the start button until you see "your score"".
lcd.setCursor(0, 1);
lcd.print("press or hold the");
lcd.setCursor(0, 2);
lcd.print("start button until");
lcd.setCursor(0, 3);
lcd.print("you see \"your score\"");
delay(5500);
lcd.clear();
delay(1000);
lcd.setCursor(0, 0);
lcd.print("TODAY'S CATEGORY IS"); //Tell the player "TODAY'S CATEGORY IS MOVIES."
delay(2000);
lcd.setCursor(7, 1);
lcd.print("MOVIES");
delay(3000);
lcd.clear();
delay(100);
lcd.setCursor(5, 0);
lcd.print("Question 1"); //Tell the player they are on Question 1.
delay(2500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("When was the first"); //Tell the player the first question "When was the first movie filmed?"
lcd.setCursor(0, 1);
lcd.print("movie filmed?");
delay(4000);
lcd.setCursor(0, 2);
lcd.print("A) 1868 B) 1878"); //Tell the player the answer options "A) 1868 B) 1878 C) 1888 D) 1918."
lcd.setCursor(0, 3);
lcd.print("C) 1888 D) 1918");
delay(500);
while (digitalRead(button_pin) == HIGH) { //This statement is only being used to create a loop around the if statement and to allow the player to skip the question.
if (digitalRead(button_a) == LOW) { //Check to see if the player selected answer A.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("C) 1888");
delay(2000);
break;
} else if (digitalRead(button_b) == LOW) { //Check to see if the player selected answer B.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("C) 1888");
delay(2000);
break;
} else if (digitalRead(button_c) == LOW) { //Check to see if the player selected answer C.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED2, HIGH);
lcd.setCursor(5, 0);
lcd.print("Correct!"); //Tell the player they are "Correct!"
Score = Score + 1; //Add 1 point to the player's total score.
delay(1500);
break;
} else if (digitalRead(button_d) == LOW) { //Check to see if the player selected answer D.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("C) 1888");
delay(2000);
break;
}
}
lcd.clear();
delay(100);
digitalWrite(LED1, LOW); //Reset the "correct" and "incorrect" light indicators.
digitalWrite(LED2, LOW);
lcd.setCursor(4, 0);
lcd.print("Your Score Is"); //Tell the player their current score.
lcd.setCursor(10, 1);
lcd.print(Score);
delay(2500);
lcd.clear();
delay(100);
lcd.setCursor(5, 0);
lcd.print("Question 2"); //Tell the player they are on Question 2.
delay(2500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("When was Home Alone"); //Tell the player the second question "When was Home Alone filmed?"
lcd.setCursor(0, 1);
lcd.print("filmed?");
delay(3000);
lcd.setCursor(0, 2);
lcd.print("A) 1980 B) 1990"); //Tell the player the answer options "A) 1980 B) 1990 C) 2000 D) 2057."
lcd.setCursor(0, 3);
lcd.print("C) 2000 D) 2057");
delay(500);
while (digitalRead(button_pin) == HIGH) { //This statement is only being used to create a loop around the if statement and to allow the player to skip the question.
if (digitalRead(button_a) == LOW) { //Check to see if the player selected answer A.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("B) 1990");
delay(2000);
break;
} else if (digitalRead(button_b) == LOW) { //Check to see if the player selected answer B.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED2, HIGH);
lcd.setCursor(5, 0);
lcd.print("Correct!"); //Tell the player they are "Correct!"
Score = Score + 1; //Add 1 point to the player's total score.
delay(1500);
break;
} else if (digitalRead(button_c) == LOW) { //Check to see if the player selected answer C.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("B) 1990");
delay(2000);
break;
} else if (digitalRead(button_d) == LOW) { //Check to see if the player selected answer D.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("B) 1990");
delay(2000);
break;
}
}
lcd.clear();
delay(100);
digitalWrite(LED1, LOW); //Reset the "correct" and "incorrect" light indicators.
digitalWrite(LED2, LOW);
lcd.setCursor(4, 0);
lcd.print("Your Score Is"); //Tell the player their current score.
lcd.setCursor(10, 1);
lcd.print(Score);
delay(2000);
lcd.clear();
delay(100);
lcd.setCursor(5, 0);
lcd.print("Question 3"); //Tell the player they are on Question 3.
delay(2500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("When was A Bugs Life"); //Tell the player the third question "When was A Bug's Life Filmed?"
lcd.setCursor(0, 1);
lcd.print("filmed?");
delay(3000);
lcd.setCursor(0, 2);
lcd.print("A) 1978 B) 2008"); //Tell the player the answer options "A) 1978 B) 2008 C) 1988 D) 1998."
lcd.setCursor(0, 3);
lcd.print("C) 1988 D) 1998");
delay(500);
while (digitalRead(button_pin) == HIGH) { //This statement is only being used to create a loop around the if statement and to allow the player to skip the question.
if (digitalRead(button_a) == LOW) { //Check to see if the player selected answer A.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("D) 1998");
delay(2000);
break;
} else if (digitalRead(button_b) == LOW) { //Check to see if the player selected answer B.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("D) 1998");
delay(2000);
break;
} else if (digitalRead(button_c) == LOW) { //Check to see if the player selected answer C.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("D) 1998");
delay(2000);
break;
} else if (digitalRead(button_d) == LOW) { //Check to see if the player selected answer D.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED2, HIGH);
lcd.setCursor(5, 0);
lcd.print("Correct!"); //Tell the player they are "Correct!"
Score = Score + 1; //Add 1 point to the player's total score.
delay(1500);
break;
}
}
lcd.clear();
delay(100);
digitalWrite(LED1, LOW); //This resets the "correct" and "incorrect" light indicators.
digitalWrite(LED2, LOW);
lcd.setCursor(4, 0);
lcd.print("Your Score Is"); //Tells the player their current score.
lcd.setCursor(10, 1);
lcd.print(Score);
delay(2000);
lcd.clear();
delay(100);
lcd.setCursor(5, 0);
lcd.print("Question 4"); //Tell the player they are on Question 4.
delay(2500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("When did Walt Disney"); //Tell the player the fourth question "When did Walt Disney die?"
lcd.setCursor(0, 1);
lcd.print("die?");
delay(3000);
lcd.setCursor(0, 2);
lcd.print("A) 1966 B) 1956"); //Tell the player the answer options "A) 1966 B) 1956 C) 1976 D) 1969."
lcd.setCursor(0, 3);
lcd.print("C) 1976 D) 1969");
delay(500);
while (digitalRead(button_pin) == HIGH) { //This statement is only being used to create a loop around the if statement and to allow the player to skip the question.
if (digitalRead(button_a) == LOW) { //Check to see if the player selected answer A.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED2, HIGH);
lcd.setCursor(5, 0);
lcd.print("Correct!"); //Tell the player they are "Correct!"
Score = Score + 1; //Add 1 point to the player's total score.
delay(1500);
break;
} else if (digitalRead(button_b) == LOW) { //Check to see if the player selected answer B.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("A) 1966");
delay(2000);
break;
} else if (digitalRead(button_c) == LOW) { //Check to see if the player selected answer C.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("A) 1966");
delay(2000);
break;
} else if (digitalRead(button_d) == LOW) { //Check to see if the player selected answer D.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("A) 1966");
delay(2000);
break;
}
}
lcd.clear();
delay(100);
digitalWrite(LED1, LOW); //Reset the "correct" and "incorrect" light indicators.
digitalWrite(LED2, LOW);
lcd.setCursor(4, 0);
lcd.print("Your Score Is"); //Tell the player their current score.
lcd.setCursor(10, 1);
lcd.print(Score);
delay(2500);
lcd.clear();
delay(100);
lcd.setCursor(5, 0);
lcd.print("Question 5"); //Tell the player they are on Question 5.
delay(2500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("What is the name of"); //Tell the player the second question "What is the name of the skyscraper in Die Hard?"
lcd.setCursor(0, 1);
lcd.print("the skyscraper in");
lcd.setCursor(0, 2);
lcd.print("Die Hard?"); //Tell the player the answer options "A) 1980 B) 1990 C) 2000 D) 2057."
delay(2000);
while (digitalRead(button_pin) == HIGH) { //This statement is only being used to create a loop around the if statement and to allow the player to skip the question.
while ((digitalRead(button_pin) == HIGH) && (digitalRead(button_a) == HIGH) && (digitalRead(button_b) == HIGH) && (digitalRead(button_c) == HIGH) && (digitalRead(button_d) == HIGH)) {
delay(1000);
if ((digitalRead(button_pin) == HIGH) && (digitalRead(button_a) == HIGH) && (digitalRead(button_b) == HIGH) && (digitalRead(button_c) == HIGH) && (digitalRead(button_d) == HIGH)) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("What is the name of");
lcd.setCursor(0, 1);
lcd.print("the skyscraper in");
lcd.setCursor(0, 2);
lcd.print("Die Hard?");
lcd.setCursor(0, 3);
lcd.print("A) Shanghai Tower");
} else {
goto bailout_1; //This is used to excape the while loop and the if statment, and procede to the scoring step.
}
delay(1000);
if ((digitalRead(button_pin) == HIGH) && (digitalRead(button_a) == HIGH) && (digitalRead(button_b) == HIGH) && (digitalRead(button_c) == HIGH) && (digitalRead(button_d) == HIGH)) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("What is the name of");
lcd.setCursor(0, 1);
lcd.print("the skyscraper in");
lcd.setCursor(0, 2);
lcd.print("Die Hard?");
lcd.setCursor(0, 3);
lcd.print("B) Nakatomi Plaza");
} else {
goto bailout_1; //This is used to excape the while loop and the if statment, and procede to the scoring step.
}
delay(1000);
if ((digitalRead(button_pin) == HIGH) && (digitalRead(button_a) == HIGH) && (digitalRead(button_b) == HIGH) && (digitalRead(button_c) == HIGH) && (digitalRead(button_d) == HIGH)) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("What is the name of");
lcd.setCursor(0, 1);
lcd.print("the skyscraper in");
lcd.setCursor(0, 2);
lcd.print("Die Hard?");
lcd.setCursor(0, 3);
lcd.print("C) Burj Khalifa");
} else {
goto bailout_1; //This is used to excape the while loop and the if statment, and procede to the scoring step.
}
delay(1000);
if ((digitalRead(button_pin) == HIGH) && (digitalRead(button_a) == HIGH) && (digitalRead(button_b) == HIGH) && (digitalRead(button_c) == HIGH) && (digitalRead(button_d) == HIGH)) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("What is the name of");
lcd.setCursor(0, 1);
lcd.print("the skyscraper in");
lcd.setCursor(0, 2);
lcd.print("Die Hard?");
lcd.setCursor(0, 3);
lcd.print("D) Lakhta Center");
} else {
goto bailout_1; //This is used to excape the while loop and the if statment, and procede to the scoring step.
}
} bailout_1:
if (digitalRead(button_a) == LOW) { //Check to see if the player selected answer A.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("B) Nakatomi Plaza");
delay(2000);
break;
} else if (digitalRead(button_b) == LOW) { //Check to see if the player selected answer B.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED2, HIGH);
lcd.setCursor(5, 0);
lcd.print("Correct!"); //Tell the player they are "Correct!"
Score = Score + 1; //Add 1 point to the player's total score.
delay(1500);
break;
} else if (digitalRead(button_c) == LOW) { //Check to see if the player selected answer C.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("B) Nakatomi Plaza");
delay(2000);
break;
} else if (digitalRead(button_d) == LOW) { //Check to see if the player selected answer D.
delay(100);
lcd.clear();
delay(100);
digitalWrite(LED1, HIGH);
lcd.setCursor(5, 0);
lcd.print("Incorrect!"); //Tell the player they are "Incorrect!"
delay(1500);
lcd.clear();
delay(100);
lcd.setCursor(0, 0);
lcd.print("The correct answer"); //Tell the player what the correct answer was.
lcd.setCursor(0, 1);
lcd.print("is...");
delay(1500);
lcd.setCursor(0, 2);
lcd.print("B) Nakatomi Plaza");
delay(2000);
break;
}
}
lcd.clear();
delay(100);
digitalWrite(LED1, LOW); //Reset the "correct" and "incorrect" light indicators.
digitalWrite(LED2, LOW);
lcd.setCursor(0, 0);
lcd.print("Your Final Score Is"); //Tell the player their final score out of the total number of questions.
lcd.setCursor(8, 1);
lcd.print(Score);
lcd.setCursor(9, 1);
lcd.print("/5");
delay(5000);
lcd.setCursor(0, 2);
lcd.print("To play again press"); //Tell the player how to restart the game and play again.
lcd.setCursor(0, 3);
lcd.print("the start button.");
}
}