Programming Homework Help
Create an Imitation of The Famous Memory Game Simon Project
Overview
For this final project your goal is to create an imitation of the famous memory game Simon. The game consists of four colored LEDs and four push buttons. A round in the game consists of the device lighting up the LEDs in a random order. The player must reproduce that order by pressing the buttons associated with the LEDs. As the game progresses, the number of buttons to be pressed increases.
If you haven’t played the game before, check this site. (Flash player required)
In the process you will:
- Review how to interface with push buttons.
- Review how to debounce a push button.
- Discover how to play sounds using a piezo buzzer.
- Make use of arrays to store game data.
- Make use of control and repetition structures for gameplay.
- Implement your own LED chaser.
- Create and make use of functions.
In the end, your system should look like the one presented below.
Functional Requirements
- This imitation of Simon does not run forever. You are only required to generate ten rounds.
- During a round the system must illuminate a number of LEDs. Each LED has an associated sound with it. For instance, in round one the system illuminates the red LED and plays the tone associated with that LED. In round two, the system illuminates two LEDs and plays the tones associated with those LEDs. Make sure to leave a second in between the light up of your LEDs.
- After illuminating all LEDs for that round, the system must wait for the appropriate amount of button presses. For instance, round one should only accept one button press and round two should accept two button presses. The user’s button press will blink the LED once and play its associated tone. If at any point the player pushed a wrong button the game is over. If the player pushed all the buttons in correct order then it’s a win.
- When the player wins (this is by pressing all the buttons correctly), the LEDs must exhibit a chaser or sequencer behavior. This should give the appearance of running lights and should be repeated indefinitely. If you are unsure what sequence to implement, you can check this link for some ideas.
- Use the buzzer to make a sound when the player presses a button.
- If the user pressed an incorrect button play an error sound, turn off all the lights, and wait indefinitely.
- Whether it’s a win or a lose the game will only be restarted by pressing the reset button on the Arduino.
- Make sure that on every game you get a different set of rounds.
Getting Started
- Download the starter file set. It will contain the following:
SimonStarter.ino
- Use your favorite IDE or editor to modify your files.
- Make use of the provided variables to complete your program. Add more if you feel you need to store additional data.
- Make sure to use functions to avoid repetition of source code.
- Add comments!
- Compile your program and play.
Technical Requirements
- You are required to avoid copy-paste repetition of code at all costs. You must use functions, control, and repetition structures to achieve this.
- You are required to use arrays to store game data.
- You are required to use constants to avoid magic numbers. You should write code that can easily be extended to accommodate more LEDs.
- You are required to create the functions
digitalReadGeneric()
,digitalWriteGeneric()
, andpinModeGeneric()
. These functions replace the Arduino’sdigitalRead()
,digitalWrite()
, andpinMode()
respectively. The function prototypes are provided below.
bool digitalReadGeneric(uint8_t pin);
void digitalWriteGeneric(uint8_t pin, bool isOn);
void pinModeGeneric(uint8_t pin, bool isOutput);
- You are required to create the function
delayGeneric()
. This function replaces the Arduino’sdelay()
. The function prototype is provided below.
void delayGeneric(unsigned long ms);
- Create a function of your own to handle the tone playing.
- Use the following steps to generate the tone for the red LED:
- Play 440 Hz for 150ms
- Wait for 1136us
- Play 440 Hz for 150ms
- Use the following steps to generate the tone for the yellow LED:
- Play 784 Hz for 150ms
- Wait for 638us
- Play 784 Hz for 150ms
- Use the following steps to generate the tone for the blue LED:
- Play 587 Hz for 150ms
- Wait for 851us
- Play 587 Hz for 150ms
- Use the following steps to generate the tone for the green LED:
- Play 880 Hz for 150ms
- Wait for 568us
- Play 880 Hz for 150ms
- The following steps will generate an error-sound:
- Play 250 Hz for 250ms
- Wait for 250ms
- Play 150 Hz for 250ms