2020-12-02 12:08 AM
I'm using 'stm32f103rc'.
I connected the button to the GPIO PIN.
If the button is still pressed, the HIGH signal will continue to occur.
So, how do you detect how long the HIGH signal has been pressed?
Because when the button is pressed for more than 0.5 seconds, you want to generate a specific function.
I lack knowledge of hardware.
Solved! Go to Solution.
2020-12-02 06:31 AM
@JMOON.1 You can use HAL_GetTick() to measure time between press and release. Like this:
uint32_t time_press = HAL_GetTick();
...
uint32_t time_release = HAL_GetTick();
if (time_release - time_press > 500 /*ms*/ ) {
do_something();
}
-- pa
2020-12-02 06:24 AM
HAL_GPIO_ReadPin will read the status of a pin. Do this periodically (perhaps in an interrupt called every 5ms) and perform logic based on those results.
2020-12-02 06:31 AM
@JMOON.1 You can use HAL_GetTick() to measure time between press and release. Like this:
uint32_t time_press = HAL_GetTick();
...
uint32_t time_release = HAL_GetTick();
if (time_release - time_press > 500 /*ms*/ ) {
do_something();
}
-- pa
2020-12-02 04:56 PM
Thanks