Simon Says Ryan Sepe

img_4468

The Project was a memory game based on numbers. The game displayed  a randomly generated number for a few seconds, then store it and reverted the displays back to zero. The player then submitted the number they think is the correct number and then check it against the stored number. If it was wrong then they would get a strike and if it was right then they would be given a point and the next number to memorize. If you were wrong four times then you would lose and a frowning face would be displayed and the game would refresh afterwards. If you got four points then you would win and a smiling face would be displayed and the game would refresh.

During play, buttons would be used to move between the displays [buttonB], change the number on each of the displays [buttonA], and check the number against the stored number [buttonB].

For this game we used:

  • 3 – 7-segment Displays (Outputs)
  • 3 – Shift Registers
  • 2 – Buttons (Inputs)
  • 23 – Resistors [7 for each display; 1 for each button]
  • 2 many – Wires

The three Shift Registers, one for each display, were inter-connected, allowing us to take up only three Digital pin-ports on the Arduino (the data-, clock-, and latch-pins). Meanwhile. The buttons and Shift Registers were both connected to the same ground and 5V power line and the display connected through their respective Registers. We unfortunately did not have ti e to build an enclosure nor had much opportunity to build an enclosure due t the amount of wires

 


 

Throughout this, we ran into several difficulties. Including:

Buttons: Originally we wanted three buttons – one to move currentDisplay, one to change the number set in the currentDisplay, and one to compare the player’s guess to the stored number. Oddly, despite the code working and nothing being wrong with the physical button and it’s wiring, we couldn’t get a third button to work in any of the other ports. We got around the need for a third button by making buttonB multi-purpose.

In loop():

debouncerA.update();

debouncerB.update();

int add = debouncerA.rose();

int next = debouncerB.rose();

int check = debouncerB.fell();

While add and next came back true when their button was pressed [.rose()], check came back true when buttonB was released [.fell()]. This, along with a time-lapse [if (check && currentTime – pressTime > 2000) {pressTime being set to millis() when buttonB  is pressed (part of the  if (next) { statement], allows checkMemory(oneDisplay, twoDisplay, threeDisplay) to be run if buttonB is held down for more than 2 seconds.

 


 

If it is, then this helper function decides if a guess is correct or not:

bool checkMemory(int d1, int d2, int d3) {

int myGuess[] = {d1, d2, d3};

if (myGuess[0] == guessMe[0] && myGuess[1] == guessMe[1] && myGuess[2] == guessMe[2]) {

return 1;

} else {

return 0;

}

}

myGuess[] being the number currently on the display and guessMe[] being the stored number from the start of the round.


Another error seems to be that WIN and LOSE states won’t go back to the START (where a new number is generated) state, even though the RIGHT (state after a correct guess) does work and has near identical coding.

Doesn’t work:

if (gameState == WIN || gameState == LOSE) {

if (currentTime – endTime > 3000) {

int r1 = random( 0, 9);

int r2 = random( 0, 9);

int r3 = random( 0, 9);

setGuessMe(r1, r2, r3);

strike = 0;

score = 0;

startTime = millis();

gameState == START;

}

}

Works:

if (gameState == RIGHT) {

if (currentTime – startTime > 2000) {

if (score > 3) {

endTime = millis();

gameState = WIN;

} else {

int r1 = random( 0, 9);

int r2 = random( 0, 9);

int r3 = random( 0, 9);

setGuessMe(r1, r2, r3);

startTime = millis();

gameState = START;

}

}

}

 

Face display code:

byte text[] =

{ ~B01101110,//Y

~B01111001,//E

~B01101101,//S

~B01010100,//n

~B00111111,//o

~B01000000,//dash

~B00100011,//eye

~B00011100,//u

};

With this helper function:

void displayByt(int a, int b, int c) {

shiftOut(datapin, clockpin, MSBFIRST, a);

shiftOut(datapin, clockpin, MSBFIRST, b);

shiftOut(datapin, clockpin, MSBFIRST, c);

digitalWrite(latchpin, HIGH);

digitalWrite(latchpin, LOW);

}

Leave a comment