Ein Arduino Leonardo kann sich mittels der Keyboard.h Library als PC-USB-Keyboard ausgeben.
Ein einfaches Programm "Tippt" ein paar Buchstaben auf dem PC.
Bei der Verwendung von Keyboard.h ist Vorsicht geboten.
Wenn Ihr Tastenbefehle automatisch sendet, landen diese natürlich im aktuellaktiven Programm.
Wenn der Arduino im Tastatur-Modus ist nimmt diese ggf. keineNeuprogrammierung an. Durch einen 2-fach Reset (RST + GND) hat ihr jedochein kurzes Zeitfenster um ein Programm neu aufzuspielen.
Wenn Ihr zusätzlich noch "Ausführliche Ausgabe während [x] Komilierung [x]Ausgabe" aktiviert (In der Arduino IDE unter "Datei -> Voreinstellungen) hat ihrein paar mehr Sekunden Zeit nach dem Reset.
EN:
An Arduino Leonardo can be used as PC-USB keyboard using the -Keyboard.h library.
Be careful
when using Keyboard.h.
Your key commands are sent automatically to the currently active program.
If the Arduino is in keyboard mode, it may not accept reprogramming. With adouble reset (RST + GND), you have a short time window to reload a newprogram.
If you also activate "Detailed output during [x] compilation [x] output" (in theArduino IDE under "File -> Preferences) you have a few more seconds after thereset to reupload your program.
#include <Keyboard.h>
void setup(){
// Button an PIN 2
pinMode(2,INPUT_PULLUP);
Keyboard.begin();
}
void loop(){
// Warte auf Button-press
if(digitalRead(2) ==LOW) {
//Tippe "Hallo!"
Keyboard.print("Hallo!");
}