Introduction: Illuminate Your Path: a Step-by-Step Guide to Blinking 3 LEDs With STM32 Black Pill

Welcome to our instructable blog, where we embark on an illuminating journey into the realm of microcontroller programming using the powerful STM32 Black Pill. In this tutorial, we'll delve into the fascinating world of embedded systems as we learn how to blink not just one, but three LEDs in captivating patterns.

Harnessing the capabilities of the STM32 Black Pill, we'll explore the intricacies of controlling multiple LEDs and creating dynamic lighting sequences. By the end of this guide, you'll have gained valuable insights into programming microcontrollers, honed your skills in working with GPIO pins, and mastered the art of crafting mesmerizing LED patterns.

So, whether you're a seasoned enthusiast looking to expand your knowledge or a curious beginner eager to dive into the world of embedded electronics, join us as we illuminate the darkness with the brilliance of three LEDs and unlock the potential of the STM32 Black Pill. Let's get started on this electrifying adventure!

Supplies

  1. STM32 Black Pill
  2. Bread Board
  3. M-M jumper connector cables
  4. LED (3 nos.)
  5. USB TYPE-C cable


Step 1: Follow Steps 1 to 6 From My Other Blog

Step 2: Enter the Following Code in While(1) Block

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,0);

HAL_Delay(400);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,1);

HAL_Delay(400);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,0);

HAL_Delay(400);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,1);

HAL_Delay(400);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,0);

HAL_Delay(400);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,1);

HAL_Delay(400);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,0);

HAL_Delay(400);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,1);

HAL_Delay(400);




This code controls three LEDs connected to GPIO pins on an STM32 microcontroller. Let's break it down step by step:


1. `HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);`: This line turns off the LED connected to pin 13 of GPIO port C.


2. `HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,0);`: This line turns off the LED connected to pin 14 of GPIO port C.


3. `HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,0);`: This line turns off the LED connected to pin 15 of GPIO port C.


4. `HAL_Delay(400);`: This line adds a delay of 400 milliseconds, which means the program will wait for 400 milliseconds before executing the next line of code.


5. The next series of lines follows a similar pattern, but they turn on one LED at a time while keeping the others off. For example:

  - `HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);` turns off the LED on pin 13.

  - `HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,1);` turns on the LED on pin 14.

  - `HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,0);` keeps the LED on pin 15 off.

  - Then there's another delay of 400 milliseconds.


6. This sequence repeats for each LED, cycling through different combinations of LEDs being on and off.


In essence, this code creates a pattern where the LEDs connected to pins 13, 14, and 15 of GPIO port C blink in a specific sequence, with each LED turning on and off at different times. The delay between each change in LED state determines the speed of the blinking pattern.

Step 3: Follow Step 7 to 12 From My Other Blog in Order to Upload the Code to the Controller

Step 4: Results

Here are the results