Microcontroller Reaction Time Game
by charpoopoopoo in Circuits > Microcontrollers
46 Views, 0 Favorites, 0 Comments
Microcontroller Reaction Time Game
Reaction time games are a type of game that tests how quickly the player or players can respond to something such as a light turning on or a noise. It works by measuring the time between the event and the players reaction, these games are simple but can help people improve the speed in which they process information and then also the time it takes them to make a response.
My aim is to make a functional reaction time game using a Pi Pico an LED some wires and a display screen, the problem I aim to solve is how to code the Pi Pico so that it can run a functional reaction time game with an LED and a display screen
Background and research
https://www.build-electronic-circuits.com/555-timer-reaction-game/
this design uses a 555 timer that is set up in astable mode, it continuously outputs clock pulses at frequencies set by the resistor and capacitor, it then uses a CD4026 decade counter to count these pulses and update the display reguarly. when the player presses the start button the counter begins counting pulses from the 555 timer, as soon as the stop button is presses the counting stops and the last value remains on the 7 segment display
its components are a 9V battery, 555 timer, CD4026, 7 segment display, resistors, capacitors and push buttons.
the limitations are that you cant code it as all the parts are analog and have a set function, thus reducing its utility.
https://www.digikey.ie/en/maker/projects/build-a-reaction-time-mini-game-using-an-arduino/68669aa944ff4f6f8987a940f2025047?srsltid=AfmBOoqAi4VLEF9SP5qBpq3qe6GUihnq2vr8nYYUFuH2NLhE0a1JsypQ
this design uses an Arduino (microcontroller) and when the player presses the start button the Arduino chooses a random delay, after that delay an LED turns on and the player has to press the button as fast as possible, the Arduino calculates the time between the LED turning on and the player pressing the button it then shows the result on the screen display.
Components, Arduino Uno, push button, LED, resistors, jumper wires and a breadboard
a few limitations when constructing this project is its coding complexity as Arduinos require a much more specific code when compared to using Pi picos and analog parts.
Supplies
Pi Pico
LED
Wires
Momentary Push Button
LCD with I2C
70 ohms resistor
Identify Where to Place Pins
- Raspberry Pi Pico:
- GP0 connects to Pushbutton Pin 1 (in)
- GND connects to Pushbutton Pin 2 (in)
- GND connects to 16x2 I2C LCD GND
- GP1 connects to 16x2 I2C LCD SDA
- GP3 connects to 16x2 I2C LCD SCL
- VBUS connects to 16x2 I2C LCD VCC
- GP27 connects to Resistor pin2
- GND connects to LED Two Pin (Red) Cathode
- Pushbutton:
- Pin 1 (in) connects to Raspberry Pi Pico GP0
- Pin 2 (in) connects to Raspberry Pi Pico GND
- 16x2 I2C LCD:
- GND connects to Raspberry Pi Pico GND
- SDA connects to Raspberry Pi Pico GP1
- SCL connects to Raspberry Pi Pico GP3
- VCC connects to Raspberry Pi Pico VBUS
- Resistor:
- pin1 connects to LED Two Pin (Red) Anode
- pin2 connects to Raspberry Pi Pico GP27
- LED Two Pin (Red):
- Anode connects to Resistor pin1
- Cathode connects to Raspberry Pi Pico GND
The Code and What It Does
Firstly this code sets up the raspberry Pi Pico to use a Button LED and LCD screen. it processes libraries and allows randomness in the code and timing. the code allows the Pico to display messages through the LCD, measure time in milliseconds and generate code in random.it prepares the hardware for the reaction time code in the Pico.
This code sets up the LED and the Button. The code basically ensures that the button starts off and that the LCD displays "press button to start test" this tells the player that the game is ready to be started by pressing the button
This code is the heart of the reaction time game, it is the code that makes everything run smoothly. When the button is first pressed it starts of by displaying on the LCD "get ready" then waits a random 1-4 seconds, in that time randomly the LED will turn on, as soon as it lights up the player presses the button as quickly as possible. The code then calculates the reaction time in milliseconds turns the light of and displays the result on the LCD. the code then resets the game and the LCD shows "press button to start test" and waits for the button to be pressed