I'm interested in creating a seek button panel (2 buttons - back and forward) that will connect with my Android's native music player, similar to the CD player in my car.

I'd like for the buttons to have dual-operations:

  1. Seek backwards/forward in the duration of a specific track
  2. Seek backwards/forward between tracks in a playlist

I'm contemplating on how this works in my car, in order to build it on my own - is there:

A different voltage going through the circuit when the button is pressed longer


Is there some sort of timer in the micro-controller's code that tells it to send a different order when the button reaches a certain period of time being pressed?

Please pay attention to both parts of my question - how this actually works, and how should I go about building it on my own - preferably using Arduino, as per I've got one lying around.

Feel free to correct me if I'm making terminology errors - I'm more of a web kind of guy, this hardware stuff is new to me.

  • \$\begingroup\$ See the Debounce example. \$\endgroup\$ Commented Jan 27, 2014 at 15:30
  • \$\begingroup\$ What debounce example? \$\endgroup\$
    – Tom Granot
    Commented Jan 27, 2014 at 15:54
  • \$\begingroup\$ The example in the Arduino IDE. Also tutorial: if ((millis() - lastDebounceTime) > debounceDelay) { ... \$\endgroup\$ Commented Jan 27, 2014 at 16:15
  • \$\begingroup\$ OK...Will Check it, \$\endgroup\$
    – Tom Granot
    Commented Jan 27, 2014 at 16:18

2 Answers 2


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) > 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.


There is certainly NOT a different voltage applied to the button when the button is pressed longer. The firmware uses a timer to determine how long the button was pressed and what operation to perform.

Here is how you can do it. When the button is pressed (and debounced) start a timer that will expire in 250 milliseconds or so. If the button is released (and debounced) before the timer expires then cancel the timer and perform the "next track" operation. If the timer expires (i.e., the button is still pressed) then perform the "fast forward" operation. Continue fast forwarding until the button is released. (You could reconfigure the timer to expire repeatedly every 50 milliseconds or so at which point you would repeat or cancel the fast forward operation.) Once you get it working, adjust the timer periods to suit your preference.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.