0% found this document useful (0 votes)
11 views4 pages

Final Game Project Structure

The document is an Arduino sketch that implements a quiz game using three buttons and an LED. Players answer multiple-choice questions, and the score increases for correct answers, indicated by the LED lighting up. The game randomly selects the next question after each answer is checked.

Uploaded by

abinbyju1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Final Game Project Structure

The document is an Arduino sketch that implements a quiz game using three buttons and an LED. Players answer multiple-choice questions, and the score increases for correct answers, indicated by the LED lighting up. The game randomly selects the next question after each answer is checked.

Uploaded by

abinbyju1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

// Define the pins for the buttons and LED

const int button1Pin = 2;

const int button2Pin = 3;

const int button3Pin = 4;

const int ledPin = 13;

// Define the questions and answers

String question1 = "What is the capital of France?";

String answer1 = "Paris";

String question2 = "What is the largest country in the world?";

String answer2 = "Russia";

String question3 = "What is the smallest planet in our solar system?";

String answer3 = "Mercury";

// Define the current question and answer

String currentQuestion;

String currentAnswer;

// Define the score

int score = 0;

void setup() {

// Initialize the buttons and LED

pinMode(button1Pin, INPUT_PULLUP);

pinMode(button2Pin, INPUT_PULLUP);

pinMode(button3Pin, INPUT_PULLUP);

pinMode(ledPin, OUTPUT);

// Start the serial communication

Serial.begin(9600);
// Set the first question and answer

currentQuestion = question1;

currentAnswer = answer1;

// Print the first question

Serial.println(currentQuestion);

void loop() {

// Check if any of the buttons are pressed

if (digitalRead(button1Pin) == LOW) {

checkAnswer("1");

if (digitalRead(button2Pin) == LOW) {

checkAnswer("2");

if (digitalRead(button3Pin) == LOW) {

checkAnswer("3");

void checkAnswer(String buttonPressed) {

// Check if the answer is correct

if (buttonPressed == "1" && currentAnswer == answer1) {

score++;

digitalWrite(ledPin, HIGH);

delay(1000);

digitalWrite(ledPin, LOW);

nextQuestion();

if (buttonPressed == "2" && currentAnswer == answer2) {


score++;

digitalWrite(ledPin, HIGH);

delay(1000);

digitalWrite(ledPin, LOW);

nextQuestion();

if (buttonPressed == "3" && currentAnswer == answer3) {

score++;

digitalWrite(ledPin, HIGH);

delay(1000);

digitalWrite(ledPin, LOW);

nextQuestion();

void nextQuestion() {

// Choose the next question and answer

int randomNumber = random(1, 4);

if (randomNumber == 1) {

currentQuestion = question1;

currentAnswer = answer1;

if (randomNumber == 2) {

currentQuestion = question2;

currentAnswer = answer2;

if (randomNumber == 3) {

currentQuestion = question3;

currentAnswer = answer3;

}
// Print the next question

Serial.println(currentQuestion);

You might also like