webwinkelkeur logo

4.7 avg.

5151+ reviews
webwinkelkeur logoView all

5151+ reviews

5151+ reviews

Order by 16:00 for same day shipping

14 days return

EN

Individual

Business

Arduino Project: Simon Says

Beginner
25
30,45

In this Arduino project I show you how to make the game Simon says with an Arduino. Simon Says is a game where you have 4 lights that are each connected to a push button. In the beginning, one light will light up. Then you press the corresponding button. If you have pressed the correct button, the same and a next light will light up. Every time you are correct, a light is added, every time a light is added you go up a round. In this project you can adjust how many rounds you want to play. If you do not have a series correct, you have lost the game and you start over. Every time the game is played again, a random order starts.

Building and Wiring

Now we're going to put Simon Says together.

You start by connecting the positive and negative terminals of the Arduino to the positive and negative terminals of the breadboard.

Then you put the LED lights in the board. When you have done that you place a 220 ohm resistor on the plus side of each LED light, this is the longest pin.
Then you go from the minus pin of the LED lights each to its own push button.

Once you have done that, go from each button of the pin that is vertically from the minus of each led (see Fritzing diagram) to the minus of the breadboard. Then you go from each button of the pin that is diagonally from the minus of the led to the plus of the breadboard.

After this you add a wire from the diagonal pin to the minus of the leds. A2 = red, A3 = green, A1 = yellow and blue = A0.

Finally, a cable goes from the other side of the resistor to the I/O pins. From red to pin 3, from green to pin 2, from yellow to pin 4 and from blue to pin 5.

Programming

const int MAX_LVL = 10;

int volgorde[MAX_LVL];

int eigen_volg[MAX_LVL];

int LVL = 1;

int snelheid = 1000;

 

void setup(){

  pinMode(A0, INPUT);

  pinMode(A1, INPUT);

  pinMode(A2, INPUT);

  pinMode(A3, INPUT);

  pinMode(2, OUTPUT);

  pinMode(3, OUTPUT);

  pinMode(4, OUTPUT);

  pinMode(5, OUTPUT);

  digitalWrite(2, LOW);

  digitalWrite(3, LOW);

  digitalWrite(4, LOW);

  digitalWrite(5, LOW);

}

 

void loop(){

  if(LVL == 1)

  genereer_volg();

  if(digitalRead(A0) == HIGH && digitalRead(A3) == HIGH || LVL != 1){

    show_volg();

    get_volg();

  }

}

 

void show_volg(){

  digitalWrite(2, LOW);

  digitalWrite(3, LOW);

  digitalWrite(4, LOW);

  digitalWrite(5, LOW);

  for(int i = 0; i < LVL; i++){

    digitalWrite(volgorde[i], HIGH);

    delay(snelheid);

    digitalWrite(volgorde[i], LOW);

    delay(200);

  }

}

 

void get_volg(){

  int vlag = 0;

  for(int i = 0; i < LVL; i++){

    vlag = 0;

    while(vlag == 0){

      if(digitalRead(A0) == LOW){

        digitalWrite(5, HIGH);

        eigen_volg[i] = 5;

        vlag = 1;

        delay(200);

        if(eigen_volg[i] != volgorde[i]){

          verkeerde_volg();

          return;

        }

        digitalWrite(5, LOW);

      }

      if(digitalRead(A1) == LOW){

        digitalWrite(4, HIGH);

        eigen_volg[i] = 4;

        vlag = 1;

        delay(200);

        if(eigen_volg[i] != volgorde[i]){

          verkeerde_volg();

          return;

        }

        digitalWrite(4, LOW);

      }

      if(digitalRead(A2) == LOW){

        digitalWrite(3, HIGH);

        eigen_volg[i] = 3;

        vlag = 1;

        delay(200);

        if(eigen_volg[i] != volgorde[i]){

          verkeerde_volg();

          return;

        }

        digitalWrite(3, LOW);

      }

      if(digitalRead(A3) == LOW){

        digitalWrite(2, HIGH);

        eigen_volg[i] = 2;

        vlag = 1;

        delay(200);

        if(eigen_volg[i] != volgorde[i]){

          verkeerde_volg();

          return;

        }

        digitalWrite(2, LOW);

      }

    }

  }

  goede_volg();

}

 

void genereer_volg(){

  randomSeed(millis());

  for(int i = 0; i < MAX_LVL; i++){

    volgorde[i] = random(2, 6);

  }

}

 

void verkeerde_volg(){

  for(int i = 0; i < 3; i++){

    digitalWrite(2, HIGH);

    digitalWrite(3, HIGH);

    digitalWrite(4, HIGH);

    digitalWrite(5, HIGH);

    delay(250);

    digitalWrite(2, LOW);

    digitalWrite(3, LOW);

    digitalWrite(4, LOW);

    digitalWrite(5, LOW);

    delay(250);

  }

  LVL = 1;

  snelheid = 1000;

}

 

void goede_volg(){

  digitalWrite(2, LOW);

  digitalWrite(3, LOW);

  digitalWrite(4, LOW);

  digitalWrite(5, LOW);

  delay(250);

  digitalWrite(2, HIGH);

  digitalWrite(3, HIGH);

  digitalWrite(4, HIGH);

  digitalWrite(5, HIGH);

  delay(500);

  digitalWrite(2, LOW);

  digitalWrite(3, LOW);

  digitalWrite(4, LOW);

  digitalWrite(5, LOW);

  delay(250);

  if(LVL < MAX_LVL);

  LVL++;

  snelheid -= 100;

}