Reaction game

Seth Lamoreaux

Overview

For my project, I wanted to create a simple reaction based game utilizing an LCD screen module for providing feedback to a player. The idea for the game was to make it simple enough for anyone to play while still being able to compete for better scores with or without friends. Upon start-up, the LCD screen will display a prompt asking the user if they are ready to begin and the player may proceed by pressing a button. The user must then wait for a LED bulb to light up and when that happens they must press the button as fast as possible. Once the button is pressed the players score, reaction time, is displayed in either milliseconds (or seconds if it is greater than 1000 ms). From this state, the player may reset the game at any time by pressing the button a final time.

General view

Hardware

The game is built on a Silicon Labs EFM32ZG Zero Gecko ARM Cortex-M0+ microcontroller for the logic processing. For my feedback display I used a Newhaven LCD with a 16x2 character-line capacity which is also backlit for reading the prompts. The device is powered by 2xAA batteries to allow for a lightweight and compact design and has an on/off switch to save power when not being played.

Schematic Assembly

Software

The device is programmed using Kiel μVision5 in the C language. It is programmed so that it may be turned off and on from any point in the game and will reset from the beginning. Upon powering on a message displays on the board prompting the user to begin the game and will await an interrupt from the button.

After the interrupt, the user is prompted to wait until an LED lights up after a random amount of time. At this state an interrupt is set while a value is read from an array of integer values into the RTC module. The "randomness" in this case is actually an illusion of randomization as it is based on an unchanging array of integer values. Yet this would be unnoticeable to anyone who did not know this fact as the values range broadly enough so that each waiting interval feels unique.

Once the LED lights up the interrupt flag is cleared and the program will proceed to wait five seconds before ending the game and requiring the user to start over. If the button is pressed before this 5 second timeout the time stamp is collected from the timer module and is calculated in mS with an accuracy up to the thousandth of a second by the function (timerCNT*1000/109375). The score is printed to the player in mS if it is less than 1000 mS or Seconds up to the hundredth digit for a score greater than 1000 mS. From this state the game may be reset by simply pressing the button a final time.

Final Thoughts

Overall, I am happy with the final product of my project. My main source of frustration during this project was configuring the timers to reset upon each time played. If the device was turned off at the end of each game the next game would start at the correct time. If the device was not powered off then each time the game was played the next game would start the timer count from the last recorded time. This was leading to incorrect reaction times and thus an incomplete game. The only other problem I had was configuring the interrupts so that if a player kept pressing the button it would not progress the code without fully completing each state. This would lead to cases where the game would restart itself and continue without button presses due to the RTC still running from the previous game. These issues were fixed in the end and the game works as intended now. I would like to add that my only microcontroller programming experience prior to this class was in assembly language and I found that using C was much, much easier.

Downloads


Last modified:Mon, Jan 23, 2023.

00090