Simon says game using 7 segment and arduino

In the game,a sequence is displayed on the 7 segment display and you have to imitate the sequence using the switches .And if you copied the sequence correctly a message should pop up that you win and if you pressed the wrong switch a message should pop up that you lose

Have I got this right ?

You have a total of 4 different symbols.
You have a switch to represent each symbol.
At the beginning of the game, a 10 element array is populated with these symbols at random.
The entire 10 element array is displayed to the user, one symbol at a time on a single character display.
The user now has to press a button for the symbol he thinks is in the first element of the array.
If there is a match, a specific tone it played. Another tone on failure. The symbol is then displayed to the user.
That above cycle continues until all 10 symbols in the array have been tested.
A final score is presented.

If it is anything like that, you haven't got very far. gameArray[10] does not appear to be integrated in this.

Yes thats exactly what I want.How am I supposed integrate gameArray[10]?

you've probably got to do something like this (rough pseudo code):

do initialisation like initGameArray() and display stored symbol sequence to the user etc.

for ( position = 0 ; position < level ; position++ ) {
   // level here is how many of the maximum of 10 positions the user is tested with.
   wait for the user to press a key  (well debounced)
   check if the key corresponds with symbol in gameArray for that position 
   if success, play sound 1 else play sound 2 
   display the symbol in gameArray for that position 
}

wait for last digit to display
signal result to user
optionally, start next game.

Am I supposed to do this under initgameArray?

That for statement logic is intended only as pseudocode. It would ultimately be a replacement of the wait4key() logic.

What was this supposed to do ? is it a relic from the author of this software ? :

No that was a mistake

#define SW1 8
#define SW2 11
#define SW3 10
#define SW4 12

#define aSeg 2
#define bSeg 3
#define cSeg 4
#define dSeg 5
#define eSeg 6
#define fSeg 7
#define gSeg 13

#define NOTE_A4 440
#define NOTE_B4 440
#define NOTE_C3 440
#define NOTE_D4 440

int level = 5;
int position = 1;

int notes[] = {NOTE_A4, NOTE_B4, NOTE_C3, NOTE_D4};
byte displayArray[4] = {33, 3, 24, 12};
byte gameArray[10] = {1, 3, 1, 0, 2, 3, 0, 0, 1, 0};
bool DA = false;
void setup()
{

  Serial.begin(9600);
  randomSeed(analogRead(0));
  pinMode(10, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  randomSeed(analogRead(0));
  initGameArray();

  /* for(int pin=8;pin<=12;pin++){
    pinMode(pin,INPUT_PULLUP);

    }*/
  pinMode(13, OUTPUT);
}
void loop()
{
  wait4key();
  random(0, 4);
  if (DA == true) {
    //Serial.println("Init Array");
    DA = false;
  }


}
void initGameArray() {
  Serial.println("Init Array Function");
  for (int index = 0; index < 10; index++) {
    // gameArray[index]=random(0,4);
  }
  for (int index = 0; index < 10; index++) {
    Serial.print(index);
    Serial.print("\t");
    Serial.print(gameArray[index]);
    Serial.print("\t");
    Serial.println(displayArray[index]);
    displaySymbol(gameArray[index]);
    delay(1000);
  }
}
void displaySymbol(byte sym) {
  digitalWrite(aSeg, bitRead(displayArray[sym], 0));
  digitalWrite(bSeg, bitRead(displayArray[sym], 1));
  digitalWrite(cSeg, bitRead(displayArray[sym], 2));
  digitalWrite(dSeg, bitRead(displayArray[sym], 3));
  digitalWrite(eSeg, bitRead(displayArray[sym], 4));
  digitalWrite(fSeg, bitRead(displayArray[sym], 5));
  digitalWrite(gSeg, bitRead(displayArray[sym], 6));
}

void wait4key() {
  for ( position = 0 ; position < level ; position++) {

    if (digitalRead(SW1) == LOW) {
      while (digitalRead(SW1) == LOW) {}
      Serial.println("SW1 Pressed");
      tone(9, notes[0], 20);
      displaySymbol(0);
      DA = true;
    }


    if (digitalRead(SW2) == LOW) {
      while (digitalRead(SW2) == LOW) {}
      Serial.println("SW2 Pressed");
      tone(9, notes[1], 20);
      displaySymbol(1);
      DA = true;
    }
    if (digitalRead(SW3) == LOW) {
      while (digitalRead(SW3) == LOW) {}
      Serial.println("SW3 Pressed");
      tone(9, notes[2], 20);
      displaySymbol(2);
      DA = true;
    }

    if (digitalRead(SW4) == LOW) {
      while (digitalRead(SW4) == LOW) {}
      Serial.println("SW4 Pressed");
      tone(9, notes[3], 20);
      displaySymbol(3);
      DA = true;
    }
  }


  /*  for(int pin=8;pin<=12;pin++){
      if(digitalRead(pin)==LOW){
        while(digitalRead(pin)==LOW){}
        Serial.print("Button Pressed=");
        Serial.println(pin-8);
        tone(11,notes[pin-8],20);
        //displaySymbol(pin-8);

      }
    }*/
}



I replaced the wait4key()logic for loop but how do I display the game Array on the 7 segment display in a way that in the first level the first symbol is displayed and the user has to copy it and in the second level the first two symbols are displayed and so on until all 10 symbols are achieved?No tones for failure and to indicate a win.

http://www.freesimon.org/ is an example of what I mean

Its similar to this but I want the the elements in the gamearray to display on the 7 segment not all at once but partly until all elements have been displayed so basically in the first level the symbol for 1 will be displayed and the user has to copy it and in the second level the first two symbols in the game array 1 and 3 will display and the user has to copy it and this continues until all 10 elements in the gameArray has been displayed.The link I shared is quit similar but instead I have a stored array and symbols to represent the colours.But how do I do this part first?

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