This was my first Arduino project, I built it based off what I learned from the early on tutorials on LED's and basic controls.
This "Whack-a-mole" game uses 7 LED's, and a joystick. There are 4 "moles", represented by the 2nd, 3rd, 4th, and 5th lights from the left on my board. One of the four lights will randomly light up and give a set amount of time to hit the corresponding direction on the joystick. I have arranged my lights so that, from left to right, the selections on the joystick are: left, up, down, right. This is just the convention that I chose, so creative and try other ones!
The two lights on the left are red and green, which indicate a incorrect or correct choice. The yellow light to the far right blinks the count for the current high score, and it indicates the score every time a run is over (whenever a wrong choice is made). Naturally, a new high score replaces the old one.
Perhaps the most complicated part of this project is the analog joystick. For both directions of the joystick, there are max values of 0 and 1024 (for mine, I had to use 1023, so if you aren't getting the selections correct, you can try that). I believe these values can be measured as well using a serial window. I simplified these input values using switch statements for both the x and y inputs. I am not sure if this is the best way to do it, but because I only needed the max values of each direction (i.e, only 4 options, 4 LED moles) I assigned integer values to each possibility: 1, 2, 3, 4 corresponding to Left, Right, Up, Down.
The difficulty levels that I have written into my code as constants, are the time in milliseconds that the person has to make a selection. You can mess around with these times to change the difficulty for your own preference. I thought about integrating a choice using buttons or maybe the joystick at the beginning of a turn, but it wasn't really worth the work as I feel it would be pretty complicated and not really user friendly.
By all means, let me know what modifications and improvements can be made! :)
Comments