The GameFSM.c module is the main file that the game runs on. In this module, there are primarily three different states: the idle state, the outputting sequence state, and the waiting for user input state. In the idle state, the state machine is waiting for 2 coins to be inserted through the coin slot before the game initiates. In the outputting sequence state, the sequence that the player has to copy after the servos stop lighting and the LED stop flashing is outputted. In the waiting for user input state, the state machine is recording the user inputs, verifying the inputs, and incrementing the score accordingly. At the end of the game, the state machine returns back to idle to output a message on the LED matrix display depending on the score that was achieved. Below is the state diagram that describes the state machine.
The button debouncing module is primarily intended to detect a button press as a singular press. A delay between registering presses was selected to be 250 ms as that was found to have the best feel during the operation of the game.
The LED service module controls what is displayed on the LED matrix during the operation of the game. There are primarily 8 events associated with this module: ES_DISPLAY_SCORE, ES_UPDATING_SCORE, ES_MESSAGE, ES_INSERT2, ES_INSERT1, ES_CONGRATS, ES_DEFEAT, and ES_UPDATING. ES_DISPLAY_SCORE displays a score of 0 at the beginning of the game. ES_UPDATING_SCORE updates the score shown on the display whenever the user enters a correct input in the sequence. ES_MESSAGE corresponds to the time out message when the user goes idle for at least 20 seconds after the game starts or when 20 seconds have passed after only 1 coin has been entered. ES_INSERT2 is the message shown on the display when during the idle state of the game when 2 coins have yet to be inputted. ES_INSERT1 is the message shown when only 1 coin has been entered. ES_CONGRATS is the message shown when the user achieves a score of at least 10. ES_DEFEAT is the message shown when the user achieves a score below 10. ES_UPDATING corresponds to the display updating and buffers between messages shown on the display.
The button event checker module checks for when the button has been pressed. This event checker module is only enabled when the game state machine is in the waiting for user input state.
The joystick event checker module checks for the joystick has been moved and registers the movement according to a specific direction (i.e. - up, down, left, right). This event checker module is only enabled when the game state machineĀ is in the waiting for user input state.
The coin slot event checker module checks for when a coin has entered the coin slot. This event checker module is only enabled when the game state machine is in the idle state.
The generate sequence service outputs the specific sequence that the user has to input after the sequence is done outputting. The sequence generated in this service is randomized and employs a combination of servo motors as well as a LED. When a servo motor is shown as part of the sequence, the servo motor is rotated to its highest angle and then rotates back to its original angle. When the LED is shown as part of the sequence, the port connected to the LED is raised high before being lowered back down to have the LED light up briefly.
The print service outputs the desired message onto the LED matrix in a scrolling manner.
The record input service records what has been inputted through the button and through the joystick as integer values. Afterwards the values are verified in the GameFSM.c to increment or output another sequence accordingly.
The shifting timer LEDs service is responsible for keeping track of when 60 seconds has passed and will call for GameFSM.c to enter the game over phase when this time period has been reached. In this service, 6 LEDs are originally lit up and 1 LED dims every 10 seconds. After 60 seconds, all of the LEDs are dim to indicate that the game has ended
This project uses the ME218 Events and Services framework, the PWM library, the AD library, and the SPI HAL. Some of the files from the framework (primarily the ones edited for this project are accessible below)