Human Interface Device (HID)

Human Interface Device (HID) ist eine Geräteklasse des USB-Standards für Computer, welche Geräte beschreibt, mit denen Benutzer direkt interagieren. Meist wird HID bei Geräten wie Tastatur, Maus, Joystick und Grafiktabletts verwendet. (Wikipedia)

Es gibt eine HID bibliothek die im Arduino eingebaut ist (“Built-in”). aber sie funktioniert nicht mit einem Arduino Uno, aber doch mit der Flora.

In Arduino, unter: Datei —> Beispiele —> 9.USB……. 

findet ihr unter anderem folgende beispiele:

KeyboardMessage >> https://www.arduino.cc/en/Tutorial/KeyboardMessageKeyboardAndMouseControl >> https://www.arduino.cc/en/Tutorial/KeyboardAndMouseControlJoystickMouseControl >> http://www.arduino.cc/en/Tutorial/JoystickMouseControl

Hier ein simples beispiel für die Flora, das folgende sensor/knopf werte in maus und keyboard eingaben umwandelt:

A9 => mouse x koordinate

A10 => mouse y koordinate

6 => “hallo“

12 => “du”

/*
VERY SIMPILE CODE
for controling mouse x,y
and tying some text

CODE inteded for a Flora V3

CIRCUIT:
analog sensor between pin9 and GND
analog sensor between pin10 and GND
digital button between pin6 and GND
digital button between pin12 and GND

MORE INFO:

keyboard library functions:
https://www.arduino.cc/reference/en/language/functions/usb/keyboard/
keyboard keys:
https://www.arduino.cc/reference/en/language/functions/usb/keyboard/keyboardmodifiers/

mouse library functions:
https://www.arduino.cc/reference/en/language/functions/usb/mouse/
*/

#include "Mouse.h"
#include "Keyboard.h"

// declare pins:
int mouseXpin = A9;
int mouseYpin = A10;
int aPin = 6;
int bPin = 12;

// create variables for storing incoming values:
int mouseXvalue = 0;
int mouseYvalue = 0;

// create two boolean variables (true, false)
// to check if the button has been pressend before:
boolean aPinPressed = false;
boolean bPinPressed = false;


void setup() {

// use internal pull-up resistors (10K Ohm):
pinMode(mouseXpin, INPUT_PULLUP);
pinMode(mouseYpin, INPUT_PULLUP);
pinMode(aPin, INPUT_PULLUP);
pinMode(bPin, INPUT_PULLUP);

Mouse.begin();
Keyboard.begin();
}


void loop() {

///////////////////////////////
// MOUSE CONTROL:
///////////////////////////////

// read analog sensor values:
mouseXvalue = analogRead(mouseXpin);
mouseYvalue = analogRead(mouseYpin);

// map values to the speed of the mouse moving.
// you can change the range to control the speed!
mouseXvalue = map(mouseXvalue, 0, 1023, 10, 0);
mouseYvalue = map(mouseYvalue, 0, 1023, 10, 0);

// move the mouse:
Mouse.move(mouseXvalue, mouseYvalue, 0);


///////////////////////////////
// KEYBOARD CONTROL:
///////////////////////////////

// check if button is pressed and has not already been pressed!
if (digitalRead(aPin) == LOW && aPinPressed == false) {
aPinPressed = true;
Keyboard.print("hallo ");
}
if (digitalRead(aPin) == HIGH) {
aPinPressed = false; // reset the variable
}

// check if button is pressed and has not already been pressed!
if (digitalRead(bPin) == LOW && bPinPressed == false) {
bPinPressed = true;
Keyboard.print("du ");
}
if (digitalRead(bPin) == HIGH) {
bPinPressed = false; // reset the variable
}

delay(20);
}

CIRCUIT:  analog sensor between pin9 and GND  analog sensor between pin10 and GND  digital button between pin6 and GND  digital button between pin12 and GND
 

MORE INFO:  

keyboard library functions:  https://www.arduino.cc/reference/en/language/functions/usb/keyboard/
 

keyboard keys:  https://www.arduino.cc/reference/en/language/functions/usb/keyboard/keyboardmodifiers/   

mouse library functions:   https://www.arduino.cc/reference/en/language/functions/usb/mouse/

ACHTUNG. wenn du dieses beispiel läufts wird es deinen computer übernehmen. du kannst aber jederzeit die Flora abstecken, um wieder kontrolle zu bekommen:-)

Ich wünsche viel Spass!!!