To Implement a Sequence Where Three LEDs Blink in Various Combinations
by qwes11_4522 in Circuits > Microcontrollers
25 Views, 0 Favorites, 0 Comments
To Implement a Sequence Where Three LEDs Blink in Various Combinations
With STM32 black pill and STM cube IDE to implement a sequence where three LEDs blink in various combinations
In this tutorial, we will delve into programming the STM32 "Black Pill" development board using STM32CubeIDE to create diverse LED blinking patterns. The Black Pill board employs the STM32F103C8T6 microcontroller, while STM32CubeIDE serves as a robust integrated development environment tailored for STM32 microcontrollers.
Supplies
- STM32 Blackpill
- 3Led's
- Breadboard
- Jumper Wire
- USB type C cable
- STM 32 Cube ide
- STM 32 Cube Programmer
Setting Up Stm Cube IDE
- Download and install STM32CubeIDE on your computer.
- Launch STM32CubeIDE and initiate a new project. a. Select "New STM32 Project" from the Quick Start menu. b. Choose your board or microcontroller (STM32F103C8) and proceed with the Next option. c. Configure project name and location, then click Finish.
Configuring the GIPO'S and LED
- In STM32CubeIDE, navigate to the "Pinout & Configuration" tab.
- Configure three GPIO pins for controlling LEDs (e.g., GPIOA Pin 0, Pin 1, Pin 2 for Red, Green, Blue LEDs).
- Set these pins as GPIO Output and enable GPIO clock.
Write the Led Blinking Code
- Navigate to the "Core" folder in the project explorer and open main.c.
- Include necessary libraries and header files.
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5,0);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,0);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,0);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,1);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,0);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,1);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5,1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,0);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,0);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,1);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,0);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,1);
HAL_Delay(1000);
Building the Project
- Connect your STM32 Black Pill board to your computer using a USB cable.
- Build the project by clicking on the hammer icon in the toolbar.
- Once the build is successful, click the play (debug) button to flash the code onto the board.
Testing the Led Blinking Pattern
- Navigate to the "Core" folder in the project explorer and open main.c.
- Include necessary libraries and header files.
Led Blinking Results
Downloads
Conclusion
The STM32 Black Pill board to control LEDs in different blinking patterns using STM32CubeIDE. we can do further by adding new patterns or modifying the existing code to create more complex LED sequences.