Help with HID USB keyboard project

Very small project. First one, in fact. Which means I'm just starting to get my head around the environment, etc. So I apologize in advance because this is probably going to be a very basic question.

Anyway, I built a little USB keyboard device. All it does is connect a switch to a pin and a ground and when the switch is activated, it sends the "arrow down" key to the computer. I play piano and got the bug to build a foot operated page turning device so I can use my computer and an external screen to display music.

I connected the pedal through its 1/4" plug into a jack attached to a Sparkfun Pro Micro (USB on board already), and uploaded the basic code that identifies the pin, and sends the character upon press. Works like a charm.

However, it would be even BETTER if I could both go back and forward. To do this, I can do one of two things: first, I could attach a second pedal and repeat the code for a different pin. Easy. But now we're just adding pedals below the piano and I'd love to streamline the whole process into one pedal. Which means that I have to designate a different thing for "arrow up". This could be either a push and hold, or a double press. But I'm not sure how to do that.

Here is the pedal:

Any ideas from the Arduino vets who have built USB input devices?

My DREAM project would be this one:

Dev board with a pedal input. USB takes in a memory stick/chip with PDF files on board. Display out to external display and a way of scrolling through and selecting pdfs from the memory stick, then using pedal to navigate music.

I don't know that there are any dev boards that can drive a big high resolution computer monitor. I could, however, yank something from a computer to do it.

Another, possibly easier, fun idea would be that the Arduino has a bluetooth chip on board and can standalone rather than need to be attached to the computer displaying the music.

Anyway, first things first. How can I make one momentary switch represent more than one keystroke?

Existing code (written with second switch option, but there is no current second switch, and I don't really want one)

int pedalPinA = 9;
int pedalPinB = 3;
void setup()
pinMode(pedalPinA, INPUT);
digitalWrite(pedalPinA, HIGH);
pinMode(pedalPinB, INPUT);
digitalWrite(pedalPinB, HIGH);

void loop()
if (digitalRead(pedalPinA) == 0)
if (digitalRead(pedalPinB) == 0)

But I'm not sure how to do that.

You can record when the switch becomes pressed and when it becomes released. See the state change detection example.

Then, it is easy to take one action if the time is short and another if the time is long. Or, to determine if the times that the switch becomes pressed are close together - double tap - vs. far apart - single tap.

Thanks! I got most of the way towards implementing what you're saying and then came across an already-created library of functions that will do what I'm looking for,'s done!

It's called "OneButtonLibrary", credit here: Arduino OneButton Library

One click sends arrow down. (in the pdf viewer program, this results in page down)

Double click sends arrow up. (in the pdf viewer program I'm using, this results in page up)

Press and hold sends home, (in the pdf viewer program, this results in "go to beginning")

Here's the code:

#include <OneButton.h>

// Setup a new OneButton on pin 9.
OneButton button(9, true);

// setup code here, to run once:
void setup() {

// link the click, doubleclick, press functions to be called on various events.
} // setup

// main code here, to run repeatedly:
void loop() {
// keep watching the push button:

// You can implement other code in here or just wait a while
} // loop

// this function will be called when the button was pressed once in a short timeframe.

void click() {
Keyboard.write(KEY_DOWN_ARROW); // send a 'arrow down' to the computer via Keyboard HID

} // click

// this function will be called when the button was pressed 2 times in a short timeframe.
void doubleclick() {
Keyboard.write(KEY_UP_ARROW); // send a 'arrow up' to the computer via Keyboard HID

} // doubleclick

// this function will be called when the button is pressed and held.

void press() {
Keyboard.write(KEY_HOME); // send a 'home' to the computer via Keyboard HID

} // press

// End