Arduino Game

Intention

Using a body switch, the game functions as a reaction test. The game utilises two LEDs of different colors (Green and Blue in this example) which light up randomly. Each LED has a body switch in which on end is help by a person and the other end held by a third person, the player (the player would therefore be holding a wire for each LED). When each LED lights up the player must react by touching the person the LED light corresponds to, if the player is correct the light will turn off and after a brief delay one of the LEDs will turn on randomly. This repeats until the player gets one wrong. When the player touches the wrong person the LEDs flash four  times and then stay on until the game is reset for another turn. The purpose of the game is to turn off as many LEDs as you can before getting it wrong.

Code

void setup: Sets the LEDs as outputs and allows them to be randomly triggered.

void loop: Sets the analog read of the body switch to be touchAmount. The if statement consists of 4 possibilities. If LED 1 is on and person 1 is touched, the next pin is activated. If LED 1 is on and person 2 is touched, the LEDs flash and it is game over. If LED 2 is on and person 2 is touched, the next pin is activated. If LED 2 is on and person 1 is touched, the LEDs flash and it is game over. The Game Over option had to come first to stop people being able to touch both people at the same time and still progress through the game.

void lightRandomPin(int pinNum): If the right person is touched, this randomly lights the next LED.

void flashLED(): This is the Game Over option.

Wiring