Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
Detecting long (and short) presses in a keypad |
Posted: Mon Mar 30, 2009 7:37 am |
|
|
Hi guys,
I'm interfacing a 9 button keyboard to a PIC16F886. Every button is on an input and is pull-up to 5V. Now I'm able to detect simultaneous keypresses. That's good. But now I want to add detection for long and short presses. How can I do that?
This is my code for now:
Code: | //******************************* KEYPAD SCAN ********************************//
//B9,B8,B7,B6,B5,B4,B3,B2,B1
if ( ENABLE_KEYPAD_SCAN )
{
Key = Key + (1 * !input (BUTTON_1) ); // Button 1 = 0 + 1 * 1
delay_us (75);
Key = Key + (2 * !input (BUTTON_2) ); // Button 2
delay_us (75);
Key = Key + (4 * !input (BUTTON_3) ); // Button 3
delay_us (75);
Key = Key + (8 * !input (BUTTON_4) ); // Button 4
delay_us (75);
Key = Key + (16 * !input (BUTTON_5) ); // Button 5
delay_us (75);
Key = Key + (32 * !input (BUTTON_6) ); // Button 6
delay_us (75);
temp_button = !input (BUTTON_7); // Button 7
Key = Key + (64 * temp_button);
delay_us (75);
temp_button = !input (BUTTON_8); // Button 8
Key = Key + (128 * temp_button);
delay_us (75);
temp_button = !input (BUTTON_9); // Button 9
Key = Key + (256 * temp_button);
delay_us (75);
if ( Key != 0 && // Alles losgelaten
input (BUTTON_1) && input (BUTTON_2) && input (BUTTON_3) && input (BUTTON_4) &&
input (BUTTON_5) && input (BUTTON_6) && input (BUTTON_7) && input (BUTTON_8) &&
input (BUTTON_9))
{
Key = 0; // Reset Keycode
Send_Command_String_RS232 ( Key , 2 , make8 (key,1) , make8 (key,0) , 0 );
Keypad_Debounce_Counter_2 = 2; // Start 2 * 20ms = 40 mS debouncing
ENABLE_KEYPAD_SCAN = FALSE; // Niet meer matrix lezen
}
} |
grts |
|