Closed Mcletsplay001 closed 3 months ago
forgot to add the error (in German) : Dieses Gerät wurde angehalten, weil es Fehler gemeldet hat. (Code 43) Fehler bei einer Anforderung des USB-Gerätedeskriptors.
yes I fixt it had to change the way it recived the values
#include <Mouse.h>
#include <Keyboard.h>
const int joystickCenterX = 512; // Beispielmittelpunkt des Joysticks für die X-Achse
const int joystickCenterY = 512; // Beispielmittelpunkt des Joysticks für die Y-Achse
const int joystickDeadzone = 10; // Totzone zur Vermeidung von Drift um den Mittelpunkt
const float scalingFactor = 0.05; // Skalierungsfaktor für die Mausbewegung
void setup() {
// Starten der HID-Bibliotheken
Keyboard.begin();
Mouse.begin();
// HID().begin();
// Serielle Kommunikation initialisieren
Serial1.begin(115200); // Kommunikation mit dem IO-MCU
//Serial.begin(74880); // Debugging
}
void loop() {
if (Serial1.available()) {
char zeile[100];
Serial1.readBytesUntil('\n', zeile, 100);
zeile[strlen(zeile) - 1] = '\0';
processValues(zeile);
}
}
void processValues(char* zeile) {
int values[15];
int i = 0;
// Tokenisierung des Strings
char* token = strtok(zeile, ";");
while (token != nullptr && i < 15) {
values[i] = atoi(token); // ASCII to Integer
token = strtok(nullptr, ";");
i++;
}
// Werte in Variablen zuweisen
int blinkerR = values[0];
int blinkerL = values[1];
int WarnB = values[2];
int Hand = values[3];
int Horn = values[4];
int Z0 = values[5];
int Z1 = values[6];
int Z2 = values[7];
int Z3 = values[8];
int L1 = values[9];
int Mousex = values[10];
int Mousey = values[11];
int MouseR = values[12];
int MouseL = values[13];
int MouseM = values[14];
if (blinkerR == 1) {
Keyboard.press(KEY_KP_7);
Keyboard.release(KEY_KP_7);
}
if (blinkerL == 1) {
Keyboard.press(',');
Keyboard.release(',');
}
if (WarnB == 1) {
Keyboard.press(KEY_KP_8);
Keyboard.release(KEY_KP_8);
}
if (Hand == 1) {
Keyboard.press('p');
Keyboard.release('p');
}
if (Horn == 1) {
Keyboard.press('h');
Keyboard.release('h');
}
if (Z0 == 1) {
Keyboard.press(KEY_F20);
Keyboard.release(KEY_F20);
}
if (Z1 == 1) {
Keyboard.press(KEY_F22);
Keyboard.release(KEY_F22);
}
if (Z2 == 1) {
Keyboard.press(KEY_F23);
Keyboard.release(KEY_F23);
}
if (Z3 == 1) {
Keyboard.press(KEY_F24);
Keyboard.release(KEY_F24);
}
if (L1 == 1) {
Keyboard.press('n');
Keyboard.release('n');
}
//Serial.print(Mousex);
//Serial.println(Mousey);
int deltaX = Mousex - joystickCenterX;
int deltaY = Mousey - joystickCenterY;
if (abs(deltaX) < joystickDeadzone) deltaX = 0;
if (abs(deltaY) < joystickDeadzone) deltaY = 0;
deltaY = -deltaY;
deltaX *= scalingFactor;
deltaY *= scalingFactor;
Mouse.move(deltaX, deltaY, 0);
if (MouseR == 1) {
Mouse.press(MOUSE_RIGHT);
} else {
Mouse.release(MOUSE_RIGHT);
}
if (MouseL == 1) {
Mouse.press(MOUSE_LEFT);
} else {
Mouse.release(MOUSE_LEFT);
}
if (MouseM == 1) {
Mouse.press(MOUSE_MIDDLE);
} else {
Mouse.release(MOUSE_MIDDLE);
}
Hello I'm trining to make a HID device with a arduino Mega so far I got the Mouse to work but if I try to include the keyboard Library and restart the arduino dosn't get recognized anymore it shows up as unrecognized device My Code: