Show minor edits - Show changes to markup
Attach one end of the pushbutton to pin 4 on the Leonardo. Attach the other end it +5V. Use the resistor as a pull-down, providing a reference to ground, by attaching it from pin 4 to ground.
Once you've programmed your Leonardo, unplug the USB cable and open a text editor. Connect your Leonardo board to your computer and press the button to write in the document.
Attach one end of the pushbutton to pin 4 on the Arduino. Attach the other end to power. Use the resistor as a pull-down, providing a reference to ground, by attaching it from pin 4 to ground.
Once you've programmed your board, unplug the USB cable and open a text editor. Connect the board to your computer and press the button to write in the document.
(:div class=code :)
(:div class=code :)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/09.USB/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:div class=code :)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/09.USB/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:div class=code :) (:source lang=arduino tabwidth=4:) /*
Keyboard Button test
Sends a text string when a button is pressed.
The circuit: * pushbutton attached from pin 2 to +5V on AVR boards and to +3.3V to the Arduino Due * 10-kilohm resistor attached from pin 2 to ground
created 24 Oct 2011 modified 27 Mar 2012 by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardButton */
const int buttonPin = 2; // input pin for pushbutton int previousButtonState = HIGH; // 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)
// and it's currently pressed:
&& (buttonState == HIGH)) {
// increment the button counter
counter++;
// type out a message
Keyboard.print("You pressed the button ");
Keyboard.print(counter);
Keyboard.println(" times.");
}
// save the current button state for comparison next time:
previousButtonState = buttonState;
}
(:sourceend:)
When the button is pressed in this example, a text string is sent to the computer as keyboard input. The string reports the number of times the button has been pressed. Once you have the Leonardo programmed and wired up, open up your favorite text editor to see the results.
When the button is pressed in this example, a text string is sent to the computer as keyboard input. The string reports the number of times the button has been pressed. Once you have the Leonardo programmed and wired up, open up your favourite text editor to see the results.
* pushbutton attached from pin 2 to +5V * 10-kilohm resistor attached from pin 4 to ground
* pushbutton attached from pin 2 to +5V on AVR boards and to +3.3V to the Arduino Due * 10-kilohm resistor attached from pin 2 to ground
const int buttonPin = 4; // input pin for pushbutton
const int buttonPin = 2; // input pin for pushbutton
const int buttonPin = 2; // input pin for pushbutton
const int buttonPin = 4; // input pin for pushbutton
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/09.USB(Leonardo)/Keyboard/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:source lang=arduino tabwidth=4:) /*
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
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardButton */
const int buttonPin = 2; // input pin for pushbutton int previousButtonState = HIGH; // 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)
// and it's currently pressed:
&& (buttonState == HIGH)) {
// increment the button counter
counter++;
// type out a message
Keyboard.print("You pressed the button ");
Keyboard.print(counter);
Keyboard.println(" times.");
}
// save the current button state for comparison next time:
previousButtonState = buttonState;
}
(:sourceend:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/09.Keyboard/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/09.USB(Leonardo)/Keyboard/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
NB: When you use the Keybaord.print() command, the Arduino takes over your computer's keyboard! To insure you don't lose control of your computer while running a sketch with this function, make sure to set up a reliable control system before you call Keyboard.print(). This sketch includes a pushbutton to toggle the keyboard, so that it only runs after a button is depressed.
NB: When you use the Keyboard.print() command, the Arduino takes over your computer's keyboard! To insure you don't lose control of your computer while running a sketch with this function, make sure to set up a reliable control system before you call Keyboard.print(). This sketch includes a pushbutton to toggle the keyboard, so that it only runs after the button is pressed.
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/9.Keyboard/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/09.Keyboard/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:include LeonardoSeeAlsoInclude:)
(:sourceend:)
\\
Circuit
Circuit\\
(:sourceend:)
Attach one end of the pushbutton to pin 4 on the Leonardo. Attach the other end it +5V. Use the resistor as a pull-down, providing a reference to ground, by attaching it from pin 4 to ground.
Once you've programmed your Leonardo, unplug the USB cable and open a text editor. Connect your Leonardo board to your computer and press the button to write in the document.
click the images to enlarge
Attach one end of the pushbutton to pin 4 on the Leonardo. Attach the other end it +5V. Use the resistor as a pull-down, providing a reference to ground, by attaching it from pin 4 to ground.
Once you've programmed your Leonardo, unplug the USB cable and open a text editor. Connect your Leonardo board to your computer and press the button to write in the document.
click the images to enlarge
Connect your Leonardo board to your computer with a micro-USB cable. Attach one end of the pushbutton to pin 4 on the Leonardo. Attach the other end it +5V. Use the resistor as a pull-down, providing a reference to ground, by attaching it from pin 4 to ground.
Attach one end of the pushbutton to pin 4 on the Leonardo. Attach the other end it +5V. Use the resistor as a pull-down, providing a reference to ground, by attaching it from pin 4 to ground.
Once you've programmed your Leonardo, unplug the USB cable and open a text editor. Connect your Leonardo board to your computer and press the button to write in the document.
\\
\\
See Also
NB: When you use the Keybaord.print() command, the Arduino takes over your computer's keyboard! To insure you don't lose control of your computer while running a sketch with this function, make sure to set up a reliable control system before you call Keyboard.move(). This sketch includes a pushbutton to toggle the keyboard, so that it only runs after a button is depressed.
NB: When you use the Keybaord.print() command, the Arduino takes over your computer's keyboard! To insure you don't lose control of your computer while running a sketch with this function, make sure to set up a reliable control system before you call Keyboard.print(). This sketch includes a pushbutton to toggle the keyboard, so that it only runs after a button is depressed.
NB: When you use the Keybaord.print() command, the Arduino takes over your computer's keyboard! To insure you don't lose control of your computer while running a sketch with this function, make sure to set up a reliable control system before you call Keyboard.move(). This sketch includes a pushbutton to toggle the keyboard, so that it only runs after a button is depressed.
(:source http://github.com/arduino/Arduino/raw/master/libraries/Keyboard/examples/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/9.Keyboard/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/libraries/Keyboard/Examples/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/libraries/Keyboard/examples/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/libraries/Keyboard/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/libraries/Keyboard/Examples/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:)
(:div class=circuit:)
click the images to enlarge
Attach:KeyboardMessage_bb.png Δ Δ image developed using Fritzing. For more circuit examples, see the Fritzing project page
(:divend:)
Examples > Keyboard Library
When the button is pressed in this example, a text string is sent to the computer as keyboard input. The string reports the number of times the button has been pressed. Once you have the Leonardo programmed and wired up, open up your favorite text editor to see the results.
(:div class=BOM :) Hardware Required
Software Required
(:divend:)
Circuit Connect your Leonardo board to your computer with a micro-USB cable. Attach one end of the pushbutton to pin 4 on the Leonardo. Attach the other end it +5V. Use the resistor as a pull-down, providing a reference to ground, by attaching it from pin 4 to ground.
Code
(:div class=code :) (:source http://github.com/arduino/Arduino/raw/master/libraries/Keyboard/KeyboardMessage/KeyboardMessage.ino lang=arduino tabwidth=4:) (:divend:)
\\