Perfect Timing is an reflex game built on the STM32F407 (RT-Spark board). The player tries to press a button at exactly the same as a target time with a margin of error of.100 milliseconds. The MCU measures timing and shows results on a 16×2 I²C LCD and gives audio/visual feedback (green LED for success, red LED for fail, buzzer tones). The project demonstrates GPIO interrupts, hardware timers, PWM sound, I²C display use, and a simple IoT upload path.
Hardware: Wiring & Assembly- GND → GND
- VCC → 5V
- SDA → PB7 (I2C data line)
- SCL → PB6 (I2C clock line)
These pins allow the LCD to communicate with the STM32 through the I²C interface.
External Components to STM32Push Button:
- GND → GND
- Data → PG3
Red LED:
- (+ ) → 220Ω resistor → PG2
- (–) → GND
Green LED:
- (+) → 220Ω resistor → PG4
- (–) → GND
We launched STM32CubeIDE and created a new project. From the Start menu, we selected “New STM32 Project” and chose the STM32F407ZGT6 microcontroller used by the RT-Spark board. After entering the project name and saving location, we proceeded with the default initialization settings.
Step 2: Configuring GPIO PinsInside STM32CubeIDE, we opened the Pinout & Configuration tab. Following the RT-Spark schematic, we assigned the required pins for the sensors, button, and indicators used in the Perfect Timing game.
Configured pins were:
- PB7 – SDA
- PB6 – SCL
- PC1 – Internal Button (Down)
- PG3 – External Button
- PG2 – External Red LED
- PG4 – External Green LED
We also enabled the I2C peripheral since the LCD communication relies on the SDA and SCL pins.
Step 3: Writing the CodeWe navigated to the Core/Src folder and opened main.c. Here, we wrote the logic for the Perfect Timing game, including input reading, timing comparison, and LED/indicator behavior.
To support the LCD and sensor communication, we included the necessary I2C libraries by adding their .c and .h files into the project. The initialization functions generated by STM32CubeIDE helped connect the hardware configuration directly to our game logic.
After connecting the RT-Spark board to the laptop using a USB Type-C cable, we built the project using the hammer icon (Ctrl + B). Once the build completed successfully, we flashed the program by clicking the Debug button. This allowed us to test the game in real time while monitoring variables, timing, and button interaction.
Step 5: VerifyingWhen the code was successfully uploaded, the Perfect Timing game interface appeared on the LCD module. Using the configured internal and external buttons, we navigated through the menu, tested the timing challenge, and confirmed that the LEDs and game responses matched the programmed logic.
Conclusion:Through STM32CubeIDE, we were able to set up the hardware pins, integrate I2C communication, and implement the logic of the Perfect Timing game in a structured workflow. The seamless connection between the software configuration and the RT-Spark hardware allowed the game to function smoothly, displaying outputs on the LCD and responding accurately to button inputs.








Comments