-
-
Save amalbuquerque/7505755 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
/* | |
* pedal controller for Ctrl, Space and Shift | |
*/ | |
#include <Bounce.h> | |
// 10 = debounce time in ms | |
int debounceTimeMs = 10; | |
int ledPin = 11; | |
int spacePedalPin = 3; | |
int ctrlPedalPin = 2; | |
int shiftPedalPin = 1; | |
Bounce spaceBtn = Bounce(spacePedalPin, 10); | |
Bounce ctrlBtn = Bounce(ctrlPedalPin, 10); | |
Bounce shiftBtn = Bounce(shiftPedalPin, 10); | |
void setup() { | |
Serial.begin(9600); | |
pinMode(spacePedalPin, INPUT_PULLUP); | |
pinMode(ctrlPedalPin, INPUT_PULLUP); | |
pinMode(shiftPedalPin, INPUT_PULLUP); | |
pinMode(ledPin, OUTPUT); | |
Serial.println("Setup done"); | |
Keyboard.begin(); | |
delay(1000); | |
Serial.println("All set"); | |
} | |
void loop() { | |
spaceBtn.update(); | |
ctrlBtn.update(); | |
shiftBtn.update(); | |
if (spaceBtn.fallingEdge()) { | |
Keyboard.press(' '); | |
digitalWrite(ledPin, HIGH); | |
} else if (spaceBtn.risingEdge()) { | |
// 20131116, AA: comment do mattGauger antigo | |
// leave insert | |
// We have to build Ctrl-[ to leave insert since | |
// the ESC key does not seem to be detected on OSX. | |
// Keyboard.press(KEY_LEFT_CTRL); | |
// Keyboard.press('['); | |
// Keyboard.releaseAll(); | |
Keyboard.release(' '); | |
digitalWrite(ledPin, LOW); | |
} | |
// KEY_LEFT_CTRL | |
if (ctrlBtn.fallingEdge()) { | |
Keyboard.press(KEY_LEFT_CTRL); | |
digitalWrite(ledPin, HIGH); | |
} else if (ctrlBtn.risingEdge()) { | |
// Keyboard.releaseAll(); | |
Keyboard.release(KEY_LEFT_CTRL); | |
digitalWrite(ledPin, LOW); | |
} | |
// KEY_LEFT_SHIFT | |
if (shiftBtn.fallingEdge()) { | |
Keyboard.press(KEY_LEFT_SHIFT); | |
digitalWrite(ledPin, HIGH); | |
} else if (shiftBtn.risingEdge()) { | |
Keyboard.release(KEY_LEFT_SHIFT); | |
digitalWrite(ledPin, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment