Calculate the time gap between keypad inputs

Hello guys
Is there a way to measure the time gap between 1st press and 2nd press of the same button.
Reason i need to know this because i am trying to mimic the old phone keypad, I need to differentiate the different key values assigned to the same key. basically like if i press the first button twice within a specific period of time it will output B. Iv read about millis (), it only gives the start time and current time of the program but what I need is a run time mechanism measure the time gap of single serial port.

Hope I present my question simple as possible

You can use millis() to record the time whenever a key is pressed. You can probably also use it to record when the key is released. Use the difference between two readings to calculate how long the key was pressed.

You need to post your program if you want more help.

...R

Iv read about millis (), it only gives the start time and current time of the program

Actually it only gives the number of milliseconds since the Arduino was started or last reset, but that is good enough to do what you want.

Save the millis() value when the first keypress is received. Save the millis() value when the second keypress is received. The difference will tell you the time period between them.

Robin2:
You can use millis() to record the time whenever a key is pressed. You can probably also use it to record when the key is released. Use the difference between two readings to calculate how long the key was pressed.

You need to post your program if you want more help.

...R

Indeed, Thank you very much .. I am still designing my system and trying to figure out a logic . Thank you again :slight_smile:

UKHeliBob:
Actually it only gives the number of milliseconds since the Arduino was started or last reset, but that is good enough to do what you want.

Save the millis() value when the first keypress is received. Save the millis() value when the second keypress is received. The difference will tell you the time period between them.

Thank you very much for your logic, this will definitely work now.