cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407VG Led Blink Button Problem

Zabranjeni
Associate III

Hello, i'm a new about this embedded systems, i am working with stm32f4 discovery card with HAL Library.

İ looked the GPİO topic and i want to create a program like :

When i clikt the button 3 times red led will open and when i clikc the button 5 times green led will open only.

i create "int count" and i used conditions but couldnt be success about it.

Here is the my code , can anyone help me to show right algorithm?

0693W000003RUfeQAG.png

edit :

Finally it worked :

0693W000003RUtMQAW.png

13 REPLIES 13
MM..1
Chief II

==

Read the post you literally just replied to.
If you feel a post has answered your question, please click "Accept as Solution".

Ok, it done finally 🙂

it was all about conditions (==)

0693W000003RUtWQAW.png

TJM
Senior

A slightly different approach. Assign the button to an falling edge interrupt then increment both a RED and Green counter for each button press (and there is a considerable amount of bounce). Test each counter for each led in the loop. Assuming the counters are incremented for each button press, this code will turn the RED led on and off every three button pushes and will turn the GREEN led on then off every 5 button presses. Each counter gets set to 0 as the LED gets toggled. Adjust the counters or add additional code as needed for LED control. The >=5 is just to keep the count from getting away.

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  if(Button_Counter_RED==3)

  {

  HAL_GPIO_TogglePin(LED_Red_GPIO_Port, LED_Red_Pin);

  Button_Counter_RED=0;

  }

  if(Button_Counter_Grn>=5)

  {

  HAL_GPIO_TogglePin(LED_Grn_GPIO_Port, LED_Grn_Pin);

  Button_Counter_Grn=0;

  }

  /* USER CODE END WHILE */

0693W000003RV5IQAW.jpg