我正在尝试实现单按、双按和长按功能来执行不同的功能。到目前为止,我已经理解了单按和长按的逻辑,但我不知道如何检测双按。至于代码,我已经使用计数器实现了单按和长按,但代码只停留在第一个 if 条件上。
bool single_press = false;
bool long_press = false;
if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13))
{
HAL_TIM_Base_Start(&htim2);
if ((TIM2->CNT == 20) && (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)))
{
single_press = true;
long_press = false;
}
else if ((TIM2->CNT == 799) && (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)))
{
single_press = true;
long_press = true;
}
HAL_TIM_Base_Stop(&htim2);
}
if (single_press == true && long_press == false)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, 1);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, 0);
}
else if (single_press == true && long_press == true)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, 1);
HAL_Delay(1000); …Run Code Online (Sandbox Code Playgroud) 我正在构建一个宏键盘,我尝试实现的功能之一是 Ctrl+Shift+R,但在定义中,固定 8 字节字符串中仅存在一个修饰符。如何实施额外的修饰符?