This project is a Cyclone game implementation running on an STM32F031K6 microcontroller, using a WS2812B addressable LED strip. The player's goal is to stop the green light rotating on the LED strip precisely on the central red target LED by pressing a button at the right time.
The player attempts to stop the green light, which moves circularly on the LED strip, on the fixed red target LED (defined as CENTER_LED 29 in game.c).
- Successful Stop: The player advances to the next level, and the game difficulty (speed) increases. Upon completing the hardest level (
MISSION_IMPOSSIBLE), a special winning animation is played, and the game resets. - Failed Stop: The player loses a life. When all lives are depleted, the game resets.
The player's remaining lives are indicated by 3 separate LEDs connected to the
GPIOBport.
- Microcontroller: STM32F031K6
- LED Strip: WS2812B Addressable RGB LED Strip.
- Number of LEDs Used: 59 (
Core/Inc/ws2812.h->noOfLEDs). - Target LED Index: 29 (
Core/Src/game.c->CENTER_LED).
- Number of LEDs Used: 59 (
- Button: 1 momentary push-button for player input.
- Connection: PA0 (
Core/Src/game.c->BUTTON_Pin GPIO_PIN_0,BUTTON_GPIO_Port GPIOA). - In
main.c, within theMX_GPIO_Init()function, the PA0 pin is configured for external interrupt (EXTI0_1_IRQn), Rising Edge triggered, and with a Pulldown resistor. Therefore, one terminal of the button should be connected to PA0 and the other to 3.3V.
- Connection: PA0 (
- WS2812 Data Pin: Driven via TIM3_CH1 PWM output (
Core/Inc/ws2812.h->extern TIM_HandleTypeDef htim3).- PWM and DMA settings are configured in
MX_TIM3_Init()withinmain.c. For STM32F031K6, default pins for TIM3_CH1 can be PA6, PB4, or PC6. The GPIO setting for this pin is done inHAL_TIM_MspPostInit(&htim3)(usually withinCore/Src/stm32f0xx_hal_msp.c).
- PWM and DMA settings are configured in
- Life Indicator LEDs: 3 standard LEDs (pins defined in
Core/Src/game.c):- 1st Life: PB7 (
LIFE_LED_3_PIN) - 2nd Life: PB1 (
LIFE_LED_2_PIN) - 3rd Life: PB0 (
LIFE_LED_1_PIN)
- 1st Life: PB7 (
- Brightness: LED brightness is set to
BRIGHTNESS 100(on a scale of 0-255) inCore/Src/game.c.
Responsible for driving the WS2812B LED strip.
noOfLEDs: Defines the number of LEDs (59).pwmData[]: PWM buffer containing the LED data.WS2812_SetLED(): Sets the color of a single LED.WS2812_Send(): Sends the LED data to the strip.WS2812_ResetAllLED(),WS2812_SetAllLED(): Functions to control all LEDs.
Contains the game logic and flow.
Game_Setup(): Initializes the game settings.Game_Loop(): Runs the main game loop.Game_ButtonPressCallback(): Interrupt handler called when the button is pressed.- Defines various difficulty levels (from
EASYtoMISSION_IMPOSSIBLE). - Includes functions for in-game animations (
play_cylon_animation,play_flash_animation,play_won_animation).
Includes the main program flow, hardware initializations, and interrupt dispatches.
SystemClock_Config(): Configures the system clock to 48MHz.MX_GPIO_Init(),MX_DMA_Init(),MX_TIM3_Init(): Initializes the necessary peripherals.HAL_GPIO_EXTI_Callback(): Dispatches the button interrupt toGame_ButtonPressCallback().
- Get the Project: Download or clone the project files to your computer.
- Open in IDE: Open the project in STM32CubeIDE.
- Check LED Count: Ensure the
noOfLEDsdefinition (currently 59) inCore/Inc/ws2812.hmatches the LED strip you are using.CENTER_LED(29) must be less than this value. - Hardware Connections:
- Connect the
DIN(Data Input) pin of the WS2812B LED strip to the STM32's TIM3_CH1 PWM output pin (e.g., PA6, PB4, or PC6 for STM32F031K6). - Connect the button between PA0 and 3.3V (as PA0 is configured with a pulldown resistor).
- Connect the life LEDs (PB0, PB1, PB7) to their respective pins with appropriate current-limiting resistors and to GND.
- Provide a suitable power supply for the LED strip and the STM32 (usually 5V for the strip, regulated 3.3V for the STM32). Ensure all GND lines are common.
- Connect the
- Build the Project: Compile the project from the STM32CubeIDE menu (e.g., "Project" -> "Build All").
- Flash the Microcontroller: Upload the resulting
.hexor.binfile to your STM32F031K6 microcontroller using an ST-Link programmer and suitable software (e.g., STM32CubeProgrammer). - Run: Power up the hardware and enjoy the game!


