Skip to content

Instantly share code, notes, and snippets.

@brianfeucht
Last active December 18, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianfeucht/5737159 to your computer and use it in GitHub Desktop.
Save brianfeucht/5737159 to your computer and use it in GitHub Desktop.
Requires USB HID Firmware which can be found at http://mitchtech.net/arduino-usb-hid-keyboard/ Works with Webcam Photobooth. When button1 is pushed it sends ctrl+p & F3 which triggers color photo taking. When button2 is pushed it sends ctrl+v & f7 which triggers video
#define KEY_LEFT_CTRL 0x01
#define KEY_LEFT_SHIFT 0x02
#define KEY_RIGHT_CTRL 0x10
#define KEY_RIGHT_SHIFT 0x20
const int button1Pin = 2;
const int button2Pin = 7;
const int ledPin = 13;
// Keycode 60 is F3.
// See page 55 for more http://www.usb.org/developers/devclass_docs/Hut1_11.pdf
const int f3KeyboardCode = 60;
const int f7KeyboardCode = 64;
const int vKeyboardCode = 25;
const int pKeyboardCode = 19;
int buttonState = 0;
uint8_t buf[8] = {
0 };
void setup() {
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
}
void loop() {
if(readButton(button1Pin, f3KeyboardCode, pKeyboardCode))
{
}
else if(readButton(button2Pin, f7KeyboardCode, vKeyboardCode))
{
}
else
{
digitalWrite(ledPin, LOW);
keyOff();
}
}
boolean readButton(int pin, int keyboardCode, int switchModeCode)
{
// read the state of the pushbutton value:
buttonState = digitalRead(pin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
keyOn(keyboardCode, switchModeCode);
return true;
}
return false;
}
void keyOn(int keyboardCode, int switchModeCode)
{
buf[0] = KEY_LEFT_CTRL;
buf[2] = switchModeCode;
Serial.write(buf, 8);
delay(10);
keyOff();
buf[2] = keyboardCode;
Serial.write(buf, 8);
}
void keyOff()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8);
}
@brianfeucht
Copy link
Author

Wiring diagram is from the button tutorial http://arduino.cc/en/tutorial/button

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment