Hide minor edits - Show changes to markup
This example listens for a byte coming from the serial port. When received, the Leonardo or the Due send a keystroke back to the computer. The sent keystroke is one higher than what is received, so if you send an "a" from the serial monitor, you'll receive a "b" from the Leonardo (or Due). A "1" will return a "2" and so on.
This example listens for a byte coming from the serial port. When received, the board sends a keystroke back to the computer. The sent keystroke is one higher than what is received, so if you send an "a" from the serial monitor, you'll receive a "b" from the Leonardo (or Due). A "1" will return a "2" and so on.
Connect your Leonardo or Due board to your computer with a micro-USB cable.
Once programmed, open your serial monitor and send a byte. The Leonardo will reply with a keystroke that is one number higher.
Connect your board to your computer with a micro-USB cable.
Once programmed, open your serial monitor and send a byte. The Arduino will reply with a keystroke that is one number higher.
(:source lang=arduino tabwidth=4:) /*
Keyboard test
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
Reads a byte from the serial port, sends a keystroke back. The sent keystroke is one higher than what's received, e.g. if you send a, you get b, send A you get B, and so forth.
The circuit: * none
created 21 Oct 2011 modified 27 Mar 2012 by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardSerial */
void setup() {
// open the serial port:
Serial.begin(9600);
// initialize control over the keyboard: Keyboard.begin();
}
void loop() {
// check for incoming serial data:
if (Serial.available() > 0) {
// read incoming serial data:
char inChar = Serial.read();
// Type the next ASCII value from what you received:
Keyboard.write(inChar+1);
}
}
(:sourceend:)
This example listens for a byte coming from the serial port. When received, the Leonardo send a keystroke back to the computer. The sent keystroke is one higher than what is received, so if you send an "a" from the serial monitor, you'll receive a "b" from the Leonardo. A "1" will return a "2" and so on.
This example listens for a byte coming from the serial port. When received, the Leonardo or the Due send a keystroke back to the computer. The sent keystroke is one higher than what is received, so if you send an "a" from the serial monitor, you'll receive a "b" from the Leonardo (or Due). A "1" will return a "2" and so on.
Connect your Leonardo board to your computer with a micro-USB cable.
Connect your Leonardo or Due board to your computer with a micro-USB cable.
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/9.USB(Leonardo)/Keyboard/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
(:source lang=arduino tabwidth=4:) /*
Keyboard test
Reads a byte from the serial port, sends a keystroke back. The sent keystroke is one higher than what's received, e.g. if you send a, you get b, send A you get B, and so forth.
The circuit: * none
created 21 Oct 2011 modified 27 Mar 2012 by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardSerial */
void setup() {
// open the serial port:
Serial.begin(9600);
// initialize control over the keyboard: Keyboard.begin();
}
void loop() {
// check for incoming serial data:
if (Serial.available() > 0) {
// read incoming serial data:
char inChar = Serial.read();
// Type the next ASCII value from what you received:
Keyboard.write(inChar+1);
}
}
(:sourceend:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/9.Keyboard/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/9.USB(Leonardo)/Keyboard/KeyboardSerial/KeyboardSerial.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 is designed to only send a Keyboard command after the Leonardo has received a byte over the serial port.
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 is designed to only send a Keyboard command after the Leonardo has received a byte over the serial port.
Once programmed, open your serial monitor and send a byte. The Leonardo will reply with a keystroke that is one number higher.
\\
(:include LeonardoSeeAlsoInclude:)
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.print(). This sketch is designed to only send a Keyboard command after the Leonardo has received a byte over the serial port.
(:source http://github.com/arduino/Arduino/raw/master/libraries/Keyboard/examples/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/9.Keyboard/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
Circuit
Circuit\\
(:source http://github.com/arduino/Arduino/raw/master/libraries/Keyboard/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/libraries/Keyboard/examples/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
Reads a byte from the serial port, sends a keystroke back. The sent keystroke is one higher than what's received, e.g. if you send a, you get b, send A you get B, and so forth.
This example listens for a byte coming from the serial port. When received, the Leonardo send a keystroke back to the computer. The sent keystroke is one higher than what is received, so if you send an "a" from the serial monitor, you'll receive a "b" from the Leonardo. A "1" will return a "2" and so on.
Examples > Keyboard Library
Reads a byte from the serial port, sends a keystroke back. The sent keystroke is one higher than what's received, e.g. if you send a, you get b, send A you get B, and so forth.
(:div class=BOM :) Hardware Required
Software Required
(:divend:)
Circuit Connect your Leonardo board to your computer with a micro-USB cable.
Code
(:div class=code :) (:source http://github.com/arduino/Arduino/raw/master/libraries/Keyboard/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:) (:divend:)
\\