Remember Button Sequence

Hi

(First sorry for bad english grammar)

I’m very new on programmering and I’m trying to make a memory game.

I have so far connected 5 LEDs and 5 buttons (in the final game there is supposed to be 9) and made a random sequence which light up 4 random LEDs and then stops after showing the sequence one time.

The next step is that the player presses 4 buttons depending on which LEDs lit up.

But I’m not sure how I make the computer remember which buttons the player pressed on and then compare it to the LED sequence.

Can somebody help me?

(Remember this is my first time with programmering)

Light_and_button.ino (1.67 KB)

Just store it in a buffer (array should do fine but remember on which location you stored the last value). After the necessary button pressed you then can read it back an compare :slight_smile:

[Edit] Open up the sketch. To make all way more simple, have a read about arrays. Gammons Tip 1

Setup an array to store LED sequence, eg, random turns on sequence 1, 3, 5, 4, 2. Save these numbers in your array in that order.

When buttons are pressed, save the order in the same way in another array.

Then compare each position in the two arrays to see if they are the same.

Weedpharma

weedpharma:
Setup an array to store LED sequence, eg, random turns on sequence 1, 3, 5, 4, 2. Save these numbers in your array in that order.

When buttons are pressed, save the order in the same way in another array.

Then compare each position in the two arrays to see if they are the same.

Weedpharma

But how do I save the order?

I tried with case and serial.println but it didn’t work :frowning:

Because you save them in order in the array… An array isn’t going to shuffle itself…

Ok, in case your googles are broken...
Try these

http://playground.arduino.cc/Main/SimpleSimonSays

lastchancename:
Ok, in case your googles are broken...
Try these

http://www.instructables.com/id/Arduino-Simple-Simon-Says-Game/

http://playground.arduino.cc/Main/SimpleSimonSays

http://www.instructables.com/id/Arduino-Simon-Says/

I found these. But it's not quite the same game. My teacher looked at it aswell and said that I couldn't use the codes from the Simon says game.

Why not? Isn't what you want to do a Simon Says?

No not Simon Says where it lit up one more LED everytime you press the correct sequence.

I want 4 LEDs to light up (as I have made so far) and then you press 4 buttons. And then the game goes back to start.

So you only have to remember the 4 LEDs one time and then a new random sequence comes up when you press the start button.

Okay, then you only have to remove the increasing part... Don't think to hard! If you get a sandwich and there is tomato on it and you don't want tomato but you do want a sandwich, do you just trow away the sandwich or just remove the tomato?

And you can also just look at the code and figure out how they did it. You can learn from that, so don't be scared :wink: