| ??? 08/21/08 21:41 Modified: 08/21/08 21:43 Read: times |
#157649 - One way to debounce Responding to: ???'s previous message |
You might do:
#define DEBOUNCE_COUNT 10
unsigned get_key(void) {
static unsigned char old_key = KEY_NONE;
unsigned char key;
unsigned char debounce = 0xff;
while (!timeout) {
key = kdb_poll();
if (old_key != key) {
old_key = key;
debounce = 0;
} else if (key != KEY_NONE && key != KEY_INVALID && debounce != 0xff && debounce < DEBOUNCE_COUNT) {
return key;
}
}
return KEY_NONE;
}
Then you use your current code - minus all the while loops for debounce etc as implementation for kbd_poll(). Skip timeout handling if you are ok with waiting forever. Skip KEY_INVALID logic if it doesn't matter if multiple keys are pressed. Quite easy to extend with auto-repeat if you fancy that. |
| Topic | Author | Date |
| problem in 8x8 keypad | 01/01/70 00:00 | |
| I see ... | 01/01/70 00:00 | |
| this code with correction | 01/01/70 00:00 | |
| Try the Insert Code button. | 01/01/70 00:00 | |
| code with comment | 01/01/70 00:00 | |
| Lots of things to look into | 01/01/70 00:00 | |
| reply | 01/01/70 00:00 | |
| One way to debounce | 01/01/70 00:00 | |
| One Suggestion | 01/01/70 00:00 | |
| the easy way to do keypads | 01/01/70 00:00 | |
| indent, indent, indent | 01/01/70 00:00 | |
| problem in keypad | 01/01/70 00:00 | |
| Where is the code? | 01/01/70 00:00 | |
| code of 8x8 keypad | 01/01/70 00:00 | |
Simplify and think about debounce | 01/01/70 00:00 |



