23 September 2019

It Doesn't Work

This project was a grand (mis)adventure. First, I attempted to create what is known as a "Lights Out" puzzle, where all lights are on in a grid and you need to turn them all off. Pushing a button/light turns that one off and causes a state change to those adjacent to it. So, if they are on they'll turn off and if they are already off they'll infuriatingly turn on. I thought, "Hey, I've always wanted to know how to do this, I'll give it a try! It will probably be a little challenging, but it's basically just coding state changes so I kinda know the objective!" Here's a basic sketch of what I had in mind:

This is basically how the game works - the rules are easy but success is difficult and usually involves a lot of guesswork........

After several attempts at wiring and fitting a 3x3 grid of LEDs and corresponding buttons on the board, I realized I had made a major oversight: how was I going to individually program 18 components with the 13 pins of an Arduino?? I didn't know how to get the Arduino to recognize individual LEDs on a string attached to one data pin, which was rather essential. Also, it was kind of a mess at this point anyway.

Feeling only a moderate amount of discouragement, I decided to try to make a different game: Simon Says. Series of colors lights up, push the corresponding buttons in order. I thought, "This will be so much easier! I can just use a few LEDs, create a sequence, then track when the correct buttons are pushed!" If you're wondering how I'm going to do that last part, you probably know what's going to happen later.

Here's a simple sketch of my simple idea that definitely wouldn't be too complicated to make:

Simple mockup of LED and button sequences for victory


Ultimately I ended up adding a "start" button that triggers the sequence and game. I did not add a "victory" light for... reasons (you'll see). I placed everything on the breadboard like so:

Arrangement on breadboard

Schematic

I wanted to keep the board clean looking and leave space for people to push the buttons and clearly see the lights (aaaand limit the mess I had made at this point with the accumulating pile of difficult-to-read resistors) so I used "INPUT_PULLUP" instead of putting resistors between the buttons and pins.

For the code, I set up a variable called "score" and used a series of "if/else" statements to try to track correct button pushes. If incorrect, all the lights would flash and the game would reset. The problem is, for some reason I have yet to understand, "score" was not registering, so any button push triggered the reset state. I Googled and experimented and tested and isolated code to make sure it did what I wanted, all to no avail.

In the end, my frustration led me to the final version of the game: you can try playing Simon Says, but the buttons don't do what you want. Enjoy!


Here's the code I ended up using, including the remnants of the original "score" code I couldn't get to work.


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.