View previous topic :: View next topic |
Author |
Message |
ritchie
Joined: 13 Sep 2003 Posts: 87
|
A Push Button Algorithm Inquiry? |
Posted: Wed Feb 18, 2004 7:18 am |
|
|
Hello der!!!
Just a curiousity, What if I have a button-- when I press and hold it off course it will display a character corresponding to a keypress.
Is their an alogorithm when I press and hold the button it will only register one keypress for that specific button?
I need your comments, suggestions, sample snippets if any.
Thanx |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Wed Feb 18, 2004 7:54 am |
|
|
Do a search on debouncing. |
|
|
Jeprox Guest
|
|
Posted: Thu Feb 19, 2004 5:12 pm |
|
|
You don't mean debouncing, do you, because it's simply a matter of putting a delay or a few scans before finally reading it, with each scan doing a comparison with the previous read.
A simple approach (there are many ways of doing it) is to put a flag, declared as a short int, that will check if the button is pressed, and sets a flag.
short int flag= 0;
int value;
//assuming your push button is tied to Vcc through a resistor.
if((input(PUSH_BUTTON) != 1) && count==0)
{
printf("%d\r\n", value );
flag = 1;
}
if(input(PUSH_BUTTON))
flag = 0; |
|
|
|