Paja

Icon

Rapid prototyping for music, art and design work

Simple quiz

Basic idea is to ask quenstions from usen and whether the answer is right – green led will light up or if the answers wrong – red led will light up. It also counts the amount of right answers. It’s easy to continue quiz with further questions since right now there’s only one. Setup1Setup2Setup3

Pii Paappanen

Facebook Twitter Email

Category: Media Lab Helsinki, Student Projects

Tagged:

One Response

  1. ppaappan says:

    The code:

    //Questionnaire by Pii Paappanen 2007
    //Thanks to Miska for the if-answered routine and
    //* SERIAL COM – HANDELING MULTIPLE BYTES inside ARDUINO – 01_simple version
    //by beltran berrocal

    int serIn; //var that will hold the bytes in read from the serialBuffer
    int ledPin13 = 13; // LED connected to digital pin 13
    int ledPin12 = 12; // LED connected to digital pin 12
    int question_answered = 1; // whether the question’s answered or not

    void setup() {
    beginSerial(9600);
    pinMode(ledPin13, OUTPUT); // sets the digital pin as output
    pinMode(ledPin12, OUTPUT); // sets the digital pin as output
    }

    //auto go_to_the_line function
    void printNewLine() {
    printByte(13);
    printByte(10);
    }

    void loop () {
    char name = (‘x’);
    int age = (0);
    //simple feedback from Arduino
    if (question_answered == 1)
    {
    printString(“What is the name of president of Finland? \n”);
    printString(“Is it A: Tarja \n”);
    printString(“or is it B: Juho-kusti \n”);
    question_answered = 0;
    }
    printNewLine();
    // only if there are bytes in the serial buffer execute the following code
    if(serialAvailable()) {
    //inform that Arduino heard you saying something
    printString(“You answered: “);
    //keep reading and printing from serial untill there are bytes in the serial buffer
    while (serialAvailable() > 0 ) {
    name = serialRead(); //read Serial
    Serial.println(name);
    if (name == ‘A’) {
    digitalWrite(ledPin12, HIGH); // sets the LED on
    Serial.println(“Right! \n”);
    delay (2000);
    digitalWrite(ledPin12, LOW);
    // indicates that the question has been answered
    question_answered = 1;
    }
    else {
    Serial.println(name);
    digitalWrite(ledPin13, HIGH); // sets the LED on
    Serial.println(“Wrong! \n”);
    delay (2000);
    digitalWrite(ledPin13, LOW);
    }
    }
    }
    }

Social links powered by Ecreative Internet Marketing