Skip to content

Instantly share code, notes, and snippets.

@raster
Last active October 4, 2015 21:58
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 raster/2705780 to your computer and use it in GitHub Desktop.
Save raster/2705780 to your computer and use it in GitHub Desktop.
Simple two button control with a Teensy #2
/*
* TeensyTwoButtons.pde
*
* You must select Keyboard from the "Tools > USB Type" menu
*
* Download and install the Bounce library: http://www.pjrc.com/teensy/td_libs_Bounce.html
*
*/
#include <Bounce.h>
Bounce button1 = Bounce(1, 10);
Bounce button2 = Bounce(2, 10);
void setup() {
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
}
void loop() {
button1.update();
button2.update();
if (button1.fallingEdge()) {
Keyboard.set_key1(KEY_SPACE);
Keyboard.send_now();
}
if (button1.risingEdge()) {
releasekey();
}
if (button2.fallingEdge()) {
Keyboard.set_key1(KEY_ESC);
Keyboard.send_now();
}
if (button2.risingEdge()) {
releasekey();
}
}
void releasekey() {
Keyboard.set_key1(0);
Keyboard.send_now();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment