Skip to content

Instantly share code, notes, and snippets.

@johnschimmel
Created August 4, 2012 15:22
Show Gist options
  • Save johnschimmel/3258336 to your computer and use it in GitHub Desktop.
Save johnschimmel/3258336 to your computer and use it in GitHub Desktop.
SimpleKeyboard for Arduino Leonardo
/*
Keyboard Button test
Sends a text string when a button is pressed.
The circuit:
* pushbutton attached from pin 2 to +5V
* 10-kilohm resistor attached from pin 4 to ground
created 24 Oct 2011
modified 27 Mar 2012
by Tom Igoe
modified by john schimmel 2012-08-04
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardButton
*/
const int buttonPin = 13; // input pin for pushbutton
int previousButtonState = LOW; // for checking the state of a pushButton
int counter = 0; // button push counter
void setup() {
// make the pushButton pin an input:
pinMode(buttonPin, INPUT);
// initialize control over the keyboard:
Keyboard.begin();
}
void loop() {
// read the pushbutton:
int buttonState = digitalRead(buttonPin);
// if the button state has changed,
if ((buttonState != previousButtonState) && (buttonState == LOW)) {
// type out a message
Keyboard.print("A");
}
// save the current button state for comparison next time:
previousButtonState = buttonState;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment