# Remember Button Sequence

**URL:** <https://forum.arduino.cc/t/remember-button-sequence/382628>\
**Category:** Programming\
**Created:** [April 28, 2016, 8:18am UTC](https://forum.arduino.cc/t/remember-button-sequence/382628 "2016-04-28T08:18:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cecilie1610](https://avatars.discourse-cdn.com/v4/letter/c/47e85d/32.png) [@Cecilie1610](https://forum.arduino.cc/u/Cecilie1610)\
**Post date:** [April 28, 2016, 8:18am UTC](https://forum.arduino.cc/t/remember-button-sequence/382628/1 "2016-04-28T08:18:24Z")

</div>

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](https://forum.arduino.cc/uploads/short-url/yDzfqp0mCSK7MhoNSVITIiNNRKs.ino) (1.67 KB)

---

<div class="post-metadata">

**Author:** ![septillion](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@septillion](https://forum.arduino.cc/u/septillion)\
**Post date:** [April 28, 2016, 8:27am UTC](https://forum.arduino.cc/t/remember-button-sequence/382628/2 "2016-04-28T08:27:24Z")

</div>

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 🙂

[Edit] Open up the sketch. To make all way more simple, have a read about arrays. [Gammons Tip 1](http://www.gammon.com.au/tips#tip1)

---

<div class="post-metadata">

**Author:** ![weedpharma](https://avatars.discourse-cdn.com/v4/letter/w/ee7513/32.png) [@weedpharma](https://forum.arduino.cc/u/weedpharma)\
**Post date:** [April 28, 2016, 8:30am UTC](https://forum.arduino.cc/t/remember-button-sequence/382628/3 "2016-04-28T08:30:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cecilie1610](https://avatars.discourse-cdn.com/v4/letter/c/47e85d/32.png) [@Cecilie1610](https://forum.arduino.cc/u/Cecilie1610)\
**Post date:** [April 28, 2016, 8:41am UTC](https://forum.arduino.cc/t/remember-button-sequence/382628/4 "2016-04-28T08:41:32Z")

</div>

> 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 ☹

---

<div class="post-metadata">

**Author:** ![septillion](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@septillion](https://forum.arduino.cc/u/septillion)\
**Post date:** [April 28, 2016, 8:43am UTC](https://forum.arduino.cc/t/remember-button-sequence/382628/5 "2016-04-28T08:43:41Z")

</div>

Because you save them in order in the array... An array isn't going to shuffle itself...

---

<div class="post-metadata">

**Author:** ![lastchancename](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/lastchancename/32/215426_2.png) [@lastchancename](https://forum.arduino.cc/u/lastchancename)\
**Post date:** [April 28, 2016, 8:49am UTC](https://forum.arduino.cc/t/remember-button-sequence/382628/6 "2016-04-28T08:49:34Z")

</div>

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

> **[Arduino - Simple Simon Says Game](https://www.instructables.com/Arduino-Simple-Simon-Says-Game/)**
>
> Arduino - Simple Simon Says Game: In this instructable, I will show you how to make a simple Simon Says Game using an Arduino. it's not just simple but we can get a psychological benefit. I have a bad memory to remember something fast or a new...

[http://playground.arduino.cc/Main/SimpleSimonSays](http://playground.arduino.cc/Main/SimpleSimonSays)

> **[Arduino Simon Says](https://www.instructables.com/Arduino-Simon-Says/)**
>
> Arduino Simon Says: In this Instructable I'll show you how to put together a very simple Simon Says Game using an Arduino Micro Controller. I first started this project back in 2010 and haven't picked it up again since. Much has changed in the world...

---

<div class="post-metadata">

**Author:** ![Cecilie1610](https://avatars.discourse-cdn.com/v4/letter/c/47e85d/32.png) [@Cecilie1610](https://forum.arduino.cc/u/Cecilie1610)\
**Post date:** [April 28, 2016, 8:52am UTC](https://forum.arduino.cc/t/remember-button-sequence/382628/7 "2016-04-28T08:52:30Z")

</div>

> lastchancename:  
> Ok, in case your googles are broken...  
> Try these
> 
> [http://www.instructables.com/id/Arduino-Simple-Simon-Says-Game/](http://www.instructables.com/id/Arduino-Simple-Simon-Says-Game/)
> 
> [Arduino Playground - HomePage](http://playground.arduino.cc/Main/SimpleSimonSays)
> 
> [http://www.instructables.com/id/Arduino-Simon-Says/](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.

---

<div class="post-metadata">

**Author:** ![septillion](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@septillion](https://forum.arduino.cc/u/septillion)\
**Post date:** [April 28, 2016, 8:56am UTC](https://forum.arduino.cc/t/remember-button-sequence/382628/8 "2016-04-28T08:56:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cecilie1610](https://avatars.discourse-cdn.com/v4/letter/c/47e85d/32.png) [@Cecilie1610](https://forum.arduino.cc/u/Cecilie1610)\
**Post date:** [April 28, 2016, 9:01am UTC](https://forum.arduino.cc/t/remember-button-sequence/382628/9 "2016-04-28T09:01:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![septillion](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@septillion](https://forum.arduino.cc/u/septillion)\
**Post date:** [April 28, 2016, 9:06am UTC](https://forum.arduino.cc/t/remember-button-sequence/382628/10 "2016-04-28T09:06:16Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 9:52pm UTC](https://forum.arduino.cc/t/remember-button-sequence/382628/11 "2021-05-05T21:52:05Z")

</div>


