From 2c90355ca230340417ab8d24475824f9407b060a Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Mon, 5 Mar 2012 22:30:47 -0500 Subject: [PATCH] Added new Keyboard combo examples --- .../KeyboardReprogram/KeyboardReprogram.ino | 73 +++++++++++++++++ .../KeyboardSleep/KeyboardSleep.ino | 80 +++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 build/shared/examples/9.Keyboard/KeyboardReprogram/KeyboardReprogram.ino create mode 100644 build/shared/examples/9.Keyboard/KeyboardSleep/KeyboardSleep.ino diff --git a/build/shared/examples/9.Keyboard/KeyboardReprogram/KeyboardReprogram.ino b/build/shared/examples/9.Keyboard/KeyboardReprogram/KeyboardReprogram.ino new file mode 100644 index 000000000..654862bcc --- /dev/null +++ b/build/shared/examples/9.Keyboard/KeyboardReprogram/KeyboardReprogram.ino @@ -0,0 +1,73 @@ +/* + Arduino Programs Blink + + This sketch demonstrates the Keyboard library. + + When you connect pin 12 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 D12 to ground. + + created 5 Mar 2012 + by Tom Igoe + + This example is in the public domain + + http://www.arduino.cc/en/Tutorial/KeyboardReprogram + */ +void setup() { + // make pin 12 an input and turn on the + // pullup resistor so it goes high unless + // connected to ground: + pinMode(12, INPUT_PULLUP); +} + +void loop() { + while (digitalRead(12) == HIGH) { + // do nothing until pin 12 goes low + delay(500); + } + // new document: + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press('N'); + 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++) { + Keyboard.type(KEY_BACKSPACE); + } + // make it 1000 instead: + Keyboard.println("1000);"); + Keyboard.println("digitalWrite(13, LOW);"); + Keyboard.println("delay(1000);"); + // tidy up: + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press('T'); + Keyboard.releaseAll(); + delay(3000); + // upload code: + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press('U'); + Keyboard.releaseAll(); + + // wait for the sweet oblivion of reprogramming: + while(true); +} + + + diff --git a/build/shared/examples/9.Keyboard/KeyboardSleep/KeyboardSleep.ino b/build/shared/examples/9.Keyboard/KeyboardSleep/KeyboardSleep.ino new file mode 100644 index 000000000..2ba615992 --- /dev/null +++ b/build/shared/examples/9.Keyboard/KeyboardSleep/KeyboardSleep.ino @@ -0,0 +1,80 @@ +/* + Keyboard wake-on-interrupt + + This sketch demonstrates the Keyboard library. + + With most operating systems, when the computer is in sleep mode, + tapping the space bar will wake it up. This sketch puts your + computer to sleep, waits ten seconds, then wakes it up. + + + Circuit: + * Arduino Leonardo + * wire to connect D12 to ground. + + created 5 Mar 2012 + by Tom Igoe + + This example is in the public domain + + http://www.arduino.cc/en/Tutorial/KeyboardSleep + */ + +// give the operating systems numbers: +#define OSX 0 +#define WIN7 1 +#define WINXP 2 +#define UBUNTU 3 + +int plastform = OSX; // change this to match your platform + +void setup() { + // make pin 12 an input and turn on the + // pullup resistor so it goes high unless + // connected to ground: + pinMode(12, INPUT_PULLUP); +} + +void loop() { + while (digitalRead(12) == HIGH) { + // do nothing until pin 12 goes low + delay(500); + } + + //Put the computer to sleep: + switch (platform) { + case OSX: + Keyboard.press(KEY_LEFT_GUI); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_F12); + Keyboard.releaseAll(); + break; + case WIN7: + Keyboard.press(KEY_LEFT_GUI); + Keyboard.press(KEY_RIGHT_ARROW); + Keyboard.press(KEY_RETURN); + Keyboard.releaseAll(); + break; + case WINXP: + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_DELETE); + delay(1000); + Keyboard.type('S'); + Keyboard.type('H'); + break; + case UBUNTU: + // ubuntu keystrokes? + + break; + } + // wait ten seconds, then wake the computer back up: + delay(10000); + Keyboard.type(' '); + + // wait forever: + while(true); +} + + +