Hello,
I have been trying to make a menu, I use the enter button for turn on a Led which is the corresponded menu level. This I would like to do is that, if the user press the menu button over a second, then the enter button will operate as an exit buttton rather than enter button.
Can anyone help me for this task? Below I could illustrate my code which doesn't work.
Thank you in advance!
My first effort
int PressEnterButton (void)
{
unsigned long StartCount,EndCount,ResultCount,idleTime;
int EnterButton ,LastEnterButton ;
int state,ConfirmState = 0 ;while(true){
EnterButton = digitalRead(9);
delay(100);if(EnterButton != LastEnterButton)
{
if(!EnterButton)
{
StartCount = millis();
ConfirmState = 1;
idleTime = StartCount - EndCount;
}
else{
EndCount = millis();
ResultCount = EndCount - StartCount;
if((idleTime< 1000) && (ConfirmState == 1))
{
return state = 2;
}
else if((idleTime > 1000) && (ConfirmState == 1))
{
return state = 1;
}}
My second effort
int PressEnterButton (void)
{
unsigned long StartCount,CurrentCount,ResultCount;
int EnterButton,state,ConfirmCount = 0;EnterButton = digitalRead(9);
delay(100);
StartCount = millis();
if(EnterButton == 0)
{
while(!EnterButton)
{
CurrentCount = millis();
ConfirmCount = 1;
}
ResultCount = CurrentCount - StartCount;if(ResultCount >= 1000)
{
return state = 2;
}
else
{
return state = 1;
}}
else
{
return state = 0;
}}