Tutorial.KeyboardReprogram History

Hide minor edits - Show changes to output

October 31, 2012, at 09:53 PM by Scott Fitzgerald -
Changed lines 19-20 from:
Connect your Leonardo board to your computer with a micro-USB cable.
to:
Connect your board to your computer with a micro-USB cable.
October 31, 2012, at 09:53 PM by Scott Fitzgerald -
Changed lines 4-5 from:
This example uses the Keyboard library to open a new Arduino sketch window, send keyboard commands that type in the Blink example, and reprograms the Leonardo or the Due. After running this sketch and connecting pin2 to ground, the Leonardo (or the Due) will have a new program.
to:
This example uses the Keyboard library to open a new Arduino sketch window, send keyboard commands that type in the Blink example, and reprograms the board. After running this sketch and connecting pin2 to ground, the Arduinio will have a new program.
Changed line 10 from:
* Arduino Leonardo or Arduino Due board
to:
* Arduino Leonardo, Micro, or Due board
Changed line 31 from:
to:
Changed lines 33-35 from:
(:source lang=arduino tabwidth=4:)
/*
Arduino Programs Blink
to:

(:source http://arduino.cc/en/pub/code/master/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino lang=arduino tabwidth=4:)
Deleted lines 35-127:
This sketch demonstrates the Keyboard library.

When you connect pin 2 to ground, it creates a new
window with a key combination (CTRL-N),
then types in the Blink sketch, then auto-formats the text
using another key combination (CTRL-T), then
uploads the sketch to the currently selected Arduino using
a final key combination (CTRL-U).

Circuit:
* Arduino Leonardo or Arduino Due
* wire to connect D2 to ground.

created 5 Mar 2012
modified 29 Mar 2012
by Tom Igoe

This example is in the public domain

http://www.arduino.cc/en/Tutorial/KeyboardReprogram
*/

// use this option for OSX.
// Comment it out if using Windows or Linux:
char ctrlKey = KEY_LEFT_GUI;
// use this option for Windows and Linux.
// leave commented out if using OSX:
// char ctrlKey = KEY_LEFT_CTRL;


void setup() {
// make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
// initialize control over the keyboard:
Keyboard.begin();
}

void loop() {
while (digitalRead(2) == HIGH) {
// do nothing until pin 2 goes low
delay(500);
}
delay(1000);
// new document:
Keyboard.press(ctrlKey);
Keyboard.press('n');
delay(100);
Keyboard.releaseAll();
// wait for new window to open:
delay(1000);

// Type out "blink":
Keyboard.println("void setup() {");
Keyboard.println("pinMode(13, OUTPUT);");
Keyboard.println("}");
Keyboard.println();
Keyboard.println("void loop() {");
Keyboard.println("digitalWrite(13, HIGH);");
Keyboard.print("delay(3000);");
// 3000 ms is too long. Delete it:
for (int keystrokes=0; keystrokes < 6; keystrokes++) {
delay(500);
Keyboard.write(KEY_BACKSPACE);
}
// make it 1000 instead:
Keyboard.println("1000);");
Keyboard.println("digitalWrite(13, LOW);");
Keyboard.println("delay(1000);");
Keyboard.println("}");
// tidy up:
Keyboard.press(ctrlKey);
Keyboard.press('t');
delay(100);
Keyboard.releaseAll();
delay(3000);
// upload code:
Keyboard.press(ctrlKey);
Keyboard.press('u');
delay(100);
Keyboard.releaseAll();

// wait for the sweet oblivion of reprogramming:
while(true);
}






(:sourceend:)
October 22, 2012, at 11:23 AM by Federico -
Changed lines 4-5 from:
This example uses the Keyboard library to open a new Arduino sketch window, send keyboard commands that type in the Blink example, and reprograms the Leonardo. After running this sketch and connecting pin2 to ground, the Leonardo will have a new program.
to:
This example uses the Keyboard library to open a new Arduino sketch window, send keyboard commands that type in the Blink example, and reprograms the Leonardo or the Due. After running this sketch and connecting pin2 to ground, the Leonardo (or the Due) will have a new program.
Changed line 10 from:
* Arduino Leonardo board
to:
* Arduino Leonardo or Arduino Due board
Changed line 47 from:
* Arduino Leonardo
to:
* Arduino Leonardo or Arduino Due
May 21, 2012, at 07:52 PM by Scott Fitzgerald -
Changed line 26 from:
%height=300px%[[Attach: KeyboardReprogram_bb.png | Attach: KeyboardReprogram_bb.png]]
to:
%height=300px%[[Attach: KeyboardSerial_bb.png | Attach: KeyboardSerial_bb.png]]
May 21, 2012, at 07:48 PM by Scott Fitzgerald -
Changed lines 33-129 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/09.USB(Leonardo)/Keyboard/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
to:
(:source lang=arduino tabwidth=4:)
/*
Arduino Programs Blink

This sketch demonstrates the Keyboard library.

When you connect pin 2 to ground, it creates a new
window with a key combination (CTRL-N),
then types in the Blink sketch, then auto-formats the text
using another key combination (CTRL-T), then
uploads the sketch to the currently selected Arduino using
a final key combination (CTRL-U).

Circuit:
* Arduino Leonardo
* wire to connect D2 to ground.

created 5 Mar 2012
modified 29 Mar 2012
by Tom Igoe

This example is in the public domain

http://www.arduino.cc/en/Tutorial/KeyboardReprogram
*/

// use this option for OSX.
// Comment it out if using Windows or Linux:
char ctrlKey = KEY_LEFT_GUI;
// use this option for Windows and Linux.
// leave commented out if using OSX:
// char ctrlKey = KEY_LEFT_CTRL;


void setup() {
// make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
// initialize control over the keyboard:
Keyboard.begin();
}

void loop() {
while (digitalRead(2) == HIGH) {
// do nothing until pin 2 goes low
delay(500);
}
delay(1000);
// new document:
Keyboard.press(ctrlKey);
Keyboard.press('n');
delay(100);
Keyboard.releaseAll();
// wait for new window to open:
delay(1000);

// Type out "blink":
Keyboard.println("void setup() {");
Keyboard.println("pinMode(13, OUTPUT);");
Keyboard.println("}");
Keyboard.println();
Keyboard.println("void loop() {");
Keyboard.println("digitalWrite(13, HIGH);");
Keyboard.print("delay(3000);");
// 3000 ms is too long. Delete it:
for (int keystrokes=0; keystrokes < 6; keystrokes++) {
delay(500);
Keyboard.write(KEY_BACKSPACE);
}
// make it 1000 instead:
Keyboard.println("1000);");
Keyboard.println("digitalWrite(13, LOW);");
Keyboard.println("delay(1000);");
Keyboard.println("}");
// tidy up:
Keyboard.press(ctrlKey);
Keyboard.press('t');
delay(100);
Keyboard.releaseAll();
delay(3000);
// upload code:
Keyboard.press(ctrlKey);
Keyboard.press('u');
delay(100);
Keyboard.releaseAll();

// wait for the sweet oblivion of reprogramming:
while(true);
}






(:sourceend:)
May 02, 2012, at 04:14 PM by Scott Fitzgerald -
Changed line 33 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/09.Keyboard/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/09.USB(Leonardo)/Keyboard/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
April 27, 2012, at 06:55 PM by Scott Fitzgerald -
Changed lines 6-7 from:
'''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.'''
to:
'''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 Keyboard commands after digital pin 2 is pulled to ground.'''
April 27, 2012, at 06:36 PM by Scott Fitzgerald -
Changed lines 4-7 from:
This example uses the Keyboard library to open a new Arduino sketch window, type in the Blink example, and reprogram the Leonardo.

'''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.'''
to:
This example uses the Keyboard library to open a new Arduino sketch window, send keyboard commands that type in the Blink example, and reprograms the Leonardo. After running this sketch and connecting pin2 to ground, the Leonardo will have a new program.

'''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.'''
Changed lines 14-15 from:
*none
to:
* Arduino IDE
Changed lines 21-23 from:
To run the sketch, connect a hook-up wire from pin 2 to ground.

to:
To run the sketch, connect a hook-up wire from pin 2 to ground. For this to run successfully, keep the Arduino software running as the frontmost application.

April 27, 2012, at 06:03 PM by Scott Fitzgerald -
Added lines 24-29:
[-click the images to enlarge-]

%height=300px%[[Attach: KeyboardReprogram_bb.png | Attach: KeyboardReprogram_bb.png]]
[-image developed using [[http://www.fritzing.org |Fritzing]]. For more circuit examples, see the [[http://fritzing.org/projects/|Fritzing project page]] -]

Changed line 33 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/9.Keyboard/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/09.Keyboard/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
Changed line 40 from:
\\
to:
(:include LeonardoSeeAlsoInclude:)
April 18, 2012, at 03:34 AM by Scott Fitzgerald -
April 18, 2012, at 12:47 AM by Scott Fitzgerald -
Added lines 1-34:
''Examples > Keyboard Library''

!!!Keyboard Reprogram
This example uses the Keyboard library to open a new Arduino sketch window, type in the Blink example, and reprogram the Leonardo.

'''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.'''

(:div class=BOM :)
'''Hardware Required'''
* Arduino Leonardo board
* hookup wire

'''Software Required'''
*none

(:divend:)

'''Circuit'''\\
Connect your Leonardo board to your computer with a micro-USB cable.

To run the sketch, connect a hook-up wire from pin 2 to ground.


'''Code'''

(:div class=code :)
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/9.Keyboard/KeyboardSerial/KeyboardSerial.ino lang=arduino tabwidth=4:)
(:divend:)

'''See Also'''
*[[/Reference/KeyboardWrite | Keyboard.write]]()
*[[/Reference/KeyboardPrint | Keyboard.print]]()
*[[/Reference/KeyboardPrintln | Keyboard.println]]()
\\

Share