Fatleys Pi Pico Reaction Time Game
by Fatley in Circuits > Raspberry Pi
23 Views, 0 Favorites, 0 Comments
Fatleys Pi Pico Reaction Time Game

i am makeing a led light reaction time game with a rasberry pi pico your results will be shown on a screen conected to the pico on a breadboard it will be played with 2 people to see who gets the fastest score the code will be run thrpugh thonny and micro python
Supplies
Materials
rgb or led lights x2
pi pico rasberry pi x1
bread board x1
wires x15
screen to display the scores x1
Tools
Laptop x1
the file below is how i wired everything up and the pins i conected everything to were it needed to go
Downloads
Soldering
this can be different for everyone but for me the first thing i did was solder my arcade buttons so i can conect them to the pi pico there is a image above
Conecting All the Wires



after you have solderd the buttons its time for you to conect everything together if you dont wanna do it fron scratch use the file i uploaded earliar i also uploaded it on this step for ease of acces
Downloads
The Code
after you have done all thoes steps you will need to open the app you are running the code through i am useing Thonny
once you open it up i have listed the code down below for you to coppy and paste into Thonny
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int redButtonPin = 4; // Player 1
const int blueButtonPin = 5; // Player 2
const int redLEDPin = 10; // Player 1 win
const int greenLEDPin = 11; // GO signal
const int blueLEDPin = 12; // Player 2 win
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C LCD
unsigned long goTime = 0;
bool waitingForPress = false;
bool gameStarted = false;
void setup() {
pinMode(redButtonPin, INPUT_PULLUP);
pinMode(blueButtonPin, INPUT_PULLUP);
pinMode(redLEDPin, OUTPUT);
pinMode(greenLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);
lcd.begin();
lcd.backlight();
randomSeed(analogRead(0)); // Random seed
lcd.print("Reaction Game");
delay(2000);
}
void loop() {
if (!gameStarted) {
lcd.clear();
lcd.print("Get Ready...");
delay(1000);
int waitTime = random(2000, 5000); // 2–5 seconds
delay(waitTime);
lcd.clear();
lcd.print("GO!");
digitalWrite(greenLEDPin, HIGH); // Signal to go
goTime = millis();
waitingForPress = true;
gameStarted = true;
}
if (waitingForPress) {
if (digitalRead(redButtonPin) == LOW) {
showWinner("Player 1", redLEDPin);
} else if (digitalRead(blueButtonPin) == LOW) {
showWinner("Player 2", blueLEDPin);
}
}
}
void showWinner(String player, int ledPin) {
waitingForPress = false;
gameStarted = false;
unsigned long reactionTime = millis() - goTime;
digitalWrite(greenLEDPin, LOW);
digitalWrite(ledPin, HIGH);
lcd.clear();
lcd.print(player + " Wins!");
lcd.setCursor(0, 1);
lcd.print("Time: ");
lcd.print(reactionTime);
lcd.print(" ms");
delay(3000);
digitalWrite(ledPin, LOW);
lcd.clear();
}