2020-10-09 12:04 AM
2020-10-09 02:40 AM
Maybe you should debounce the button, as mechanical buttons bounce, i.e. may create more than one pulse per button press.
There are several techniques to do that, one of the easiest is to connect some small capacitor in parallel to the button, which together with the pull resistor forms some low pass filter. The time constant of that filter should be slightly lower than the period of the maximum speed to press that button (e.g. 100..200ms). You will find this solution also at the NUCLEO or DISCOVERY boards.
Good luck!
/Peter