A simple stm32 code to get rid of the bounce of the buttons while working with the buttons or switches. The “count” variable increases and the “button_flag” variable changes as logic 1 and 0 if we push the button or switch.
|
1 2 3 4 5 6 7 |
button = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0); //pin0 defined as button if(button) button_flag=1; if(!button&&button_flag==1){ button_flag=0; count++; //this variable increases when the button is pressed } |