Overview of Lightgame where all the components are shown.
Development Team :
Dr. Minas Dasygenis
Lightgame was made as a semester project for the course Embedded Systems of the University of western Macedonia, Department of Informatics and Telecommunications engineering.
Lightgame is a reaction game designed for four players. Each player has a button with one of the colors red, green, blue and yellow. At each round an RGB LED will light randomly one of those colors. If the player with the corresponding color presses their button, their score will be their reaction time in milliseconds. If the wrong player presses their button they will get a penalty equal to their reaction time multiplied by 2. In the end of the game each player’s score will be the sum of their reaction times and penalties. So the player with the lower score is the winner.
At the left side there is the Slave arduino with it's components and at the right side,
the Master arduino responsible for the buttons and calculations. Design The game is developed using two Arduino devices connected in a Master - Slave configuration via the I2C synchronous serial protocol. The Master Arduino is responsible for handling the buttons, displaying the correct rgb colors, doing all the calculations for the score and stages of the game. The Slave or Peripherals Arduino is responsible for displaying in a TFT LCD screen the right messages and playing the appropriate music using a buzzer based on the commands it has received from the Master Arduino.
Stage 1 : Start of the game The game works on stages which are managed by the Master Arduino. When the game begins, the game is in the first stage where the Master Arduino is initializing the score values, makes sure the RGB LED doesn’t display any colors and sends the command to the Slave arduino in order to display a game starting message and play an intro music. At this stage the player buttons are locked and will be ignored if pressed.
Stage 2 : The turns In the second stage, the game begins. At this stage the Master Arduino will send the command to the Slave arduino to display a message for a new round and play a music to alert the players, select a random color between the available ones, start a timer using the StopWatch library to count the score, allow the player buttons to be pressed and light the RGB LED. The colors, although they are randomly selected, are also made sure to allow each player to have a turn every four rounds. Once the RGB LED has light a color, the program will continue in a loop waiting to a player to press their button, this loop will last for a few seconds.
When a player button is pressed, an interrupt will be called in which we will check if the player buttons are allowed to be pressed, wether the right or a wrong button is pressed, calculate and add the reaction time to the player’s score and inform a volatile variable that the correct or a wrong button was pressed. Using this variable, the loop will end, the timer will stop and the RGB LED will turn off. Then the Master Arduino will send to the Slave Arduino the corresponding command to play a win or lose sound and display the updated score of the player who pressed their button.
A closer look at the screen and buzzer on the left and the RGB LED on the right. Stage 3 : Game over Once the turns are over, there is the third stage of the game where the Master Arduino sends to the Slave Arduino the command to display all the scores and play a game over music. At this stage the player buttons are ignored and any of the players can use the reset button to reset the game.
Aruino Source Code
The source code is freely distributed under apache 2 licence.
Master Arduino Code :
Slave Arduino Code :