Skip to content

Instantly share code, notes, and snippets.

@algrs
Created February 22, 2013 19:51
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 algrs/5016078 to your computer and use it in GitHub Desktop.
Save algrs/5016078 to your computer and use it in GitHub Desktop.
const int ledPin = 13; // Pin 13: Teensy 3.0 has the LED on pin 13
const int buttonPin = 2; // Attach a N.O. momentary pushbutton that connects to ground
const int BUTTON_UP = 0;
const int BUTTON_DOWN = 1;
int buttonState = BUTTON_UP;
elapsedMillis sincePress;
void setButtonState(int newButtonState) {
if (newButtonState != buttonState && sincePress > 100) {
if (newButtonState == BUTTON_UP) {
Keyboard.set_modifier(0);
} else {
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT | MODIFIERKEY_GUI);
}
Keyboard.send_now();
buttonState = newButtonState;
sincePress = 0;
}
}
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop()
{
if (digitalRead(buttonPin)) {
// buttonPin is high due to pullup resistor
setButtonState(BUTTON_UP);
} else {
// buttonPin is low due to pushbutton pressed
setButtonState(BUTTON_DOWN);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment