Hi, All
Can somebody help me to figure out on how to make something like this.
To Go out of a menu screen I would like to make the user hold a button for several seconds before turning back the menu will exit.
If the user presses this button quick the program will return to the top of the menu, this menu will not exit.
I hope somebody can figure this out.
I have tryed it but no succes.
Regards Jordy Kleian
Push Button Hold (1s) Little Help
Moderator: Benj
- Jordy101091
- Posts: 519
- Joined: Sat Jan 08, 2011 4:02 pm
- Location: The Netherlands
- Has thanked: 25 times
- Been thanked: 188 times
- Contact:
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
- Contact:
Re: Push Button Hold (1s) Little Help
Hi,
You just need to check your input, if it's high for let's say 200ms then it's a short pulse and if it's still on after 700ms it's a long pulse.
Hope this helps.
Nicolas
EDIT : You just need to change the two if-statements to increase or decrease the time the user needs to push the button. I did it for 200ms and 700ms but you can change that pretty easily.
You just need to check your input, if it's high for let's say 200ms then it's a short pulse and if it's still on after 700ms it's a long pulse.
Code: Select all
char counter, pulse;
counter = 0;
while ((portb & 0x01) == 1) // check portb pin 0
{
delay_ms(20); // delay 20ms
counter++; // increase counter
}
if (counter <= 10) // 200ms = 20ms * 10
{
pulse = 0; // short pulse
}
else if (counter >= 35) // 700ms = 20ms * 35
{
pulse = 1; // long pulse
}
Nicolas
EDIT : You just need to change the two if-statements to increase or decrease the time the user needs to push the button. I did it for 200ms and 700ms but you can change that pretty easily.