Simon Says (Janosch Spohner)



This game was inspired by the original Simon Says game where there is a sequence of different colored lights flashing and the user has to match that sequence by pressing the colors in the correct order. If the user did the sequence correctly then the game will do the same sequence again but this time there is one more light added. This makes each level a little bit harder because there is an extra color to remember. The game will end when the user presses the wrong button. I am not sure if there is a time limit in the Original Simon says game but I did want there to be an amount of time that the user has to press the button or else the game will end.


Inputs and Outputs

I used 4 colored buttons that matched the colors of the led’s so the user would know which button to hit for the color in the sequence. I used a white 5th button that was used to start the game or go on to the next level of the game once the sequence was completed.  To display the sequence I used 4 colored LED’s; red, blue, green and yellow. I also used an RGB LED to display the game state. The RGB would be green when the game is ready to start or go to the next level, off while the sequence is going and red when the game is over due to an error by the user. Then after a couple seconds it well reset to start a new game.



I never got that far. I should have started on this project way earlier as I decided to get a motorcycle license and take a class the weekend before this was due. I meant to work on this game after class but after learning to ride a motorcycle for 8 hours a day Saturday and Sunday I was too exhausted and Monday night I had to go back to Marietta to take the theory test for the class which meant I only had Tuesday and some of Wednesday left to work on it. At least I passed my class and can go get a Motorcycle license…



Basically the game is a state machine that has a NewGame and a GameOver state, a NextStep state which decided which LED will light up next and add it to the sequence, four other states that turn on the specific colored LED to show the sequence, and another  four states that keep track of if the user is pressing the matching button for the correct LED in the sequence. Since I was rushing this I never took the time to draw a  state diagram, I regret that decision because I kinda had an idea of what I wanted in my head but it was very difficult to make it work. I struggled a lot and spent a long time trying to figure out how to use an array to display a sequence of lights.

int pattern[100];
int patternCount;
int patternPosition;

I ended up using an array called pattern that would store numbers 1-4 which represented the LED’s. Then I used patternPosition to keep track of which number in the array I wanted to use and pattternCount was just used to know how many items where in the array.

  } else if (currentGameState == DispNextStep) {
    if (patternPosition >= patternCount) {
      currentGameState = NextStep;
      patternPosition = 0;
    } else if (currentTime - startTime > Disppause/2) {
      int lednum = pattern[patternPosition]; // chooseLed();
      if (lednum == 1) {
        currentGameState = DispredLed;
        startTime = currentTime;
      } else if (lednum == 2) {
        currentGameState = DispblueLed;
        startTime = currentTime;
      } else if (lednum == 3) {
        currentGameState = DispgreenLed;
        startTime = currentTime;
      } else if (lednum == 4) {
        currentGameState = DispyellowLed;
        startTime = currentTime;
      startTime = currentTime;

This is the section of code that decides what LED should be turned on next or if the game should go to the next level. You can see that the code first checks to see if all of the steps from the first sequence are completed. If so it will move on to the NextStep which is where the user has to press the buttons. If patternPostion is not greater than patternCount then there are still some to display and it will go ahead and do that by changing the state to one of the specific LED color states.  NextStep does basically the same thing as DispNextState except it does not display the lights and only waits for the user to press the buttons.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s