Arduino LCD quiz

Hi,

Im using an L2c display 4x20 and i’m tyring to make a little quiz.

I’d love to make a quiz with 5 questions. If you get the answere right a green led lights up
If you get the second question right a second green led lights up.
If you get the third question wrong a red led lights up.

After 5 questions right i’d like to get '‘congratz you solved the puzzle’'on my screen.
and al green leds are on

Questions could be; what kind of tree is this; Oak or Maple.
Then if you guess Oak and its right; Indeed Oak, on to question 2
And if you choose Maple; Too bad, it is an Oak, try again.

If search a lot of quiz scripts on google but nothing seem to fit for my project

Code is down below and a pic of the schematics here

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);

boolean buttonLeft;
boolean buttonRight;

void setup()
{
       pinMode(8, INPUT);  //Rechter knop buttonright
    pinMode(9, INPUT);   //Linker knop buttonLeft

    pinMode(2, OUTPUT);   //vraag 1 goed (question 1 right)  
    pinMode(3, OUTPUT);   //vraag 2 goed (question 2 right)     
    pinMode(4, OUTPUT);   //vraag 3 goed (question 3 right)    
    pinMode(5, OUTPUT);   //vraag 4 goed/right (question 4 right)
    pinMode(6, OUTPUT);   //vraag 5 goed/right(question 5 right)
       
    pinMode(7, OUTPUT);   //vraag fout/wrong (question wrong)


    

   lcd.init();
     lcd.backlight();
    lcd.setCursor(6, 1);             //Introduction welcome
    lcd.print("Welkom");
    lcd.setCursor(2, 2);
    lcd.print("beste puzzelaar!");
    delay(3000);
    lcd.clear();
     lcd.setCursor(4, 1); 
    lcd.print("Tijd voor een");
  lcd.setCursor(4, 2); 
    lcd.print("kleine quiz!");
           delay(3000);
    lcd.clear();
    lcd.setCursor(6, 0); 
    lcd.print("Ben je er");
    lcd.setCursor(5, 1); 
        lcd.print("klaar voor?");
     delay(3000);
    
    lcd.setCursor(7, 2); 
       lcd.print("3");
     delay(500);
        
         lcd.setCursor(8, 2); 
        lcd.print(".");
     delay(500);
       
         lcd.setCursor(9, 2); 
     lcd.print(".");
     delay(500);
    
    lcd.print("2");
     delay(500);
          lcd.setCursor(10, 2); 
    
        lcd.setCursor(11, 2); 
        lcd.print(".");
     delay(500);
       
         lcd.setCursor(12, 2); 
     lcd.print(".");
     delay(500);
          lcd.setCursor(13, 2); 
    lcd.print("1");
     delay(1000);
      lcd.clear();
}


void loop()
{
    buttonLeft = digitalRead(13);         // Button A
    buttonRight = digitalRead(2);       //Button B

   

If search a lot of quiz scripts on google but nothing seem to fit for my project and I don’t have a clue where to start.

Hello
What type of help do you expect ?
I´m missing your specific question.

1 Like

Well,

How do I write a code that

  • gives me a question
  • let's me choose between 2 answers
  • If the answer is right lights a green (first in row) if wrong the red led
  • after 5 right answers gives me a text congratz

Hello
Do you have expierence in system design and coding ?

A bit, i've designed the first part myself but right now i'm stuck a don't know where to start

Hello
Take my standard recipe:
As a basis, study the IPO model and then take a bag of data structures, timers and a small finite state machine and stir everything together to the desired functionality. And don't forget the seasoning.

Hello
How are the questions for the quiz provided ?

1 Like

take a piece of paper and paint your program flow in a diagram.
when you have the diagram, describe each step in short sentences.
Avoid long sentences because short sentences can be translated into code easier than long sentences.

Describe what should happen after a right answer.
Describe what should happen after a wrong answer.

How does the game end.
How does the game start.

Technically:
put your questions and answers in a struct, include a flag to indicate the right answer.
Iterate through the array and ask the questions
wait for the answer (consider a timeout?)
give the user feedback about his answer
calculate the points
repeat until the condidtion for the game end is reached.

1 Like

So here it is:

Question 1: What colour is the tree
Right: Brown
Wrong Red.

If wrong light up red led and write' sorry try again restart system"
If right light up green led1 and proceed to question 2

Question 2: What kind of tree is this?
Right: Oak
Wrong Maple

If wrong light up red led and write' sorry, try again restart system"
If right light up green led2 and proceed to question 3

...

After question 5 right
If wrong light up red led and write' sorry, try again restart system"
If right light up green led5 and write 'congratz, you solved the quiz'

Hello
Do the questions aren´t coded in the sketch, are they?

Would start by making a data structure:
1 array with the questions
1 array with the correct answers
1 array with the wrong answers (you can display them in random order)
1 array that is filled with the order of the 5 randomly chosen questions (I expect it is no fun if it is the same 5 questions all the time). You can turn the value to -1 if it is correct, and if you do wrong it generates a new stream of 5 questions.

This topic was automatically closed after 120 days. New replies are no longer allowed.