2020-09-13 02:02 AM
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?
edit :
Finally it worked :
Solved! Go to Solution.
2020-09-13 07:20 AM
==
2020-09-13 07:21 AM
2020-09-13 08:24 AM
Ok, it done finally :)
it was all about conditions (==)
2020-09-13 12:38 PM
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 */