Do you remember the game "Simon"? A lot of people my age (born in the 70s) got to lose a lot of time playing it. The game was simple, it had 4 buttons of different colors that would light up in sequence and you had to repeat the sequence. Every time, you got it right, the game would give you the sequence again with an additional color at the end.
I got one for Xmas long long ago but then I moved and moved, and moved some more so the game got lost in one of the many boxes that never get unpacked from a move to another...
As an "adult", I discovered the joys of Arduino and with that, got the opportunity to revive my long lost time wasting friend.
This tutorial will show you how to make a similar game using an Arduino Uno a few LEDs and resistors and a relatively simple circuit.
The program itself may be a little complicated for a beginner so I tried to explain in the code what it does and how.
The simplest way to get this game running is this.
1) Connect the circuit exactly as shown on the diagram. The color of the wires is not relevant so if you run out of black wires, it's ok. :)
2) Paste the source code into your favorite Arduino editor and upload it to the board
3) Play the game
The game starts after about 3 seconds with 5 slow flashes of all the LEDs.
If one or more LEDs don't flash, check the wiring. On my board, the very small buttons don't always sit properly and have a tendency of popping themselves out.
If the wiring looks right, try inverting a working LED with a non working one to see if it's wiring or the LED itself.
After the 5 flashes complete, One LED will light up. I can't tell you which, it's a surprise :) Press the button for that LED. This LED will light up again followed by a new one. Press the correct buttons in sequence... You see where I'm going with that...
Then, fairly soon, you'll see them all flash rapidly. That means you lost. :D
The last sequence you were given will play so you can count your points followed by the 5 slow blinks from earlier indicating the game is starting again.
You have 2 seconds to press each button.
There you go! Have fun!
Want to make it a little harder? Why not change the top line in the code to a different value?
#define PLAYER_WAIT_TIME 2000
Or you could add another LED, if you have one... For this, you first need to reproduce this portion of the circuit:
The orange wire here will go to any unused pin on your Arduino (Avoid 0 and 1 though)
Then modify the following lines in the code:
byte noPins = 4
byte pins[] = {2, 13, 10, 8};
if you added one LED on pin 6, the code would become
byte noPins = 5
byte pins[] = {2, 13, 10, 8, 6};
A small tip for writing Arduino code:
void setup() {
delay(3000);
Serial.begin(9600);
Reset();
}
Put a short delay as the first statement of your setup() function. It's very easy to make the Arduino go into an infinite loop or lock it up in some way. If that happens that short delay allows you reset you Arduino and upload a blank sketch before it locks up again. .
I eventually took this little idea and made it portable...
If you want to see a really cool idea for a similar (yet way more advanced) game. Check this https://www.instructables.com/id/Lego-Mini-Memory-Game by Peter Kent. He made the game on mobile with an interface to a Lego car. It's really awesome!
Comments