Simon Game- Tyler Tilton

img_1002

The inspiration for this game came from an idea I had about mixing the Simon Says game with the memory game idea.

While playing the game, a random neopixel lights up a random color, and you must find and press the correctly colored button to gain a point. You win if you get 20 points, you lose if you get 3 rounds wrong.

Click here for a video of the game play.

My inputs were six buttons, each wired to pins 7-12 respectively using one 10k resistor each. My outputs were six neopixels, wired in series similar to how they come on the strip, I just needed to space them out more. I cut them apart, then soldered them together with some wire and attached them to 5v, pin 6, and ground.

img_1009
The inside of this thing is a monstrosity. 

 

Next I built a simple 5.5in x 6.5in x 6.5in box with a slightly smaller 6in x 6in top. I used a table saw to cut an oak board I had to size and held it together using wood glue and an air nailer.

Finally the software:

I have 10 states, and three of them do the same thing, but I kind of coded myself into a corner and the way I have it set up, I can’t easily turn them into one state.

See my state diagram here:

simon-state-machine

I had a lot of challenges to overcome, and a lot of bugs to work out:

The first issue I had with the game was how to randomize both the neopixel that lights up, and the color that lights up. Randomizing the neopixel was no problem, I just needed to set a variable to random(0, 6);. The hard part was figuring out how to randomly light up a neopixel a random color out of six that I had preset. The first thing I tried was defining all of my colors using #define, and then having the program chose a random color out of an array of the colors. This almost worked, but for some reason, it was only pulling out the red value of the color. (I defined the colors using hex values, so it converted the hex to rgb, then only took the red.) Finally I realized I could use a switch case, and set up two randomized variables. It looks like this:

x = random(0, 6);
y = random(0, 6);
 
switch (x) {
 case 0: strip.setPixelColor(y, 0xff008f); strip.show(); break;
 case 1: strip.setPixelColor(y, 0x00ff00); strip.show(); break;
 case 2: strip.setPixelColor(y, 0x0000FF); strip.show(); break;
 case 3: strip.setPixelColor(y, 0xffff00); strip.show(); break;
 case 4: strip.setPixelColor(y, 0xff0000); strip.show(); break;
 case 5: strip.setPixelColor(y, 0x44146f); strip.show(); break;
}

I used a similar switch case for the GAMEBEG state.

The rest of the game is pretty basic, although when I finally got it all together there were three bugs.

The first bug I dealt with was that if you pressed any button, it would always be correct, even if it wasn’t the correctly colored button. This was a pretty easy fix once I realized that I had used “=” instead of “==” I attribute this mistake to the fact that I started writing the code when I had some down time at work, but I didn’t have my Arduino or anything to actually test with. I wrote the majority of this code before ever touching my Arduino, which is not a good habit to make…..

When I first wrote the code, the switch case above caused the neopixels to blink several times randomly while it was in the state. What I ended up doing was performing the switch case, and the immediately passed it into a hold case that would just hold the pixel on for like half a second.

The second bug I had to deal with involved a count down state that I had originally in the program. Once you pressed any button at the start of the game, all the neopixels would turn from red to yellow to green and then the game would start. For some reason, this was causing the first neopixel to always be a green color in the same place, and then if you started another game, the first pixel would never show up, so you would always lose the first round. I tried and tried to figure out what was going on here and never could. The code was pretty simple, so it really baffled me. I eventually just took out the count down sequence and it worked without a hitch. I think I like it better this way any way.

 

 

 

Leave a comment