Created
February 22, 2013 19:51
-
-
Save algrs/5016078 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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