我正在使用开关盒建立一个debounce定时器。
我输入了 "case 1",但在输入了 if (in_1_timerTimeout)
但我不知道为什么 谁能弄清楚什么是缺失?
到目前为止,我已经检查了,代码存在 "情况0 "和输入 "情况1",但它停止在那里。我有一种感觉,我可能是解释 if (in_1_timerTimeout)
错,所以我不能正常使用它。
#include "mcc_generated_files/mcc.h"
#include "stdbool.h"
unsigned long in_1_timer = 0;
unsigned long in_1_state = 0;
bool in_1_timerTimeout = false;
bool in_1 = false;
void myInterruptHandler(void)
{
}
void handleInputFilter(void)
{
switch (in_1_state)
{
case 0:
if (!in_button_GetValue())
{
in_1_timer = 1000;
in_1_timerTimeout = false;
in_1_state = 1;
}
break;
case 1:
if (!in_button_GetValue())
{
//programmet kører hertil, men kommer ikke videre til næste "if"
if (in_1_timerTimeout)
{
in_1_state = 2;
in_1 = true;
//out_LED_SetHigh();
}
} else in_1_state = 0;
break;
case 2:
if (in_button_GetValue())
{
in_1_timer = 1000;
in_1_timerTimeout = false;
in_1_state = 3;
}
break;
case 3:
if (in_button_GetValue())
{
if (in_1_timerTimeout)
{
in_1_state = 0;
in_1 = false;
//out_LED_SetLow();
}
} else in_1_state = 2;
break;
}
}
void main(void)
{
SYSTEM_Initialize();
while (1)
{
handleInputFilter();
// Add your application code
}
}
在给定的上下文中,我没有看到任何地方有 in_1_timerTimeout
被设置为true。
因此,它将总是跳过 if (in_1_timerTimeout)
因为它一直是假的。
我没看到你的切换语句有什么问题,现在的工作很好。