Detecting length of button-press using a microcontroller
To amplify Ignacio's comment

The Arduino "Debounce" example shows how to use the time (milliseconds since AVR chip powered on) to determine how long a button has (probably) been pressed.

if ((millis() - lastDebounceTime) &gt; debounceDelay) {
  ...
  if (buttonState == HIGH) {


The example does this because physical buttons typically bounce up and down several times when you press them, which can be read as multiple button presses. So you ignore any that happen faster than most humans can stab their fingers up and down.

The same technique can be used to see how long the button has been in a "down" state. You may need to refactor the logic in the example software somewhat.