How do I detect that the button connected to GPIO is still pressed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
- Labels:
-
GPIO-EXTI
-
STM32F1 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-02 6: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-02 6: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-02 6: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-02 4:56 PM
Thanks
