Problem mit arduino leonardo?
Ich wollte meine arduino leonardo als gamecontroller unter windows einbinden.
angeschlossen sind 4 potientometer an den pins A0-A3 angeschlossen.
der arduino soll diese informationen an den pc senden.
Der code lautet
```
#include <Joystick.h>
// Create the Joystick
Joystick_ Joystick;
void setup() {
// Initialize Joystick Library
Joystick.begin();
}
void loop() {
// Read the values of the potentiometers
int pot1 = analogRead(A0);
int pot2 = analogRead(A1);
int pot3 = analogRead(A2);
int pot4 = analogRead(A3);
// Map the analog values (0-1023) to joystick values (0-1023)
int joyX = map(pot1, 0, 1023, 0, 1023);
int joyY = map(pot2, 0, 1023, 0, 1023);
int joyZ = map(pot3, 0, 1023, 0, 1023);
int joyR = map(pot4, 0, 1023, 0, 1023);
// Set the joystick axis values
Joystick.setXAxis(joyX);
Joystick.setYAxis(joyY);
Joystick.setZAxis(joyZ);
Joystick.setRxAxis(joyR);
// Add a small delay to allow for smooth operation
delay(10);
}
Ich hoffe mir kann jemand helfen
Viele grüße
1 Antwort
Und was genau geht nicht? Hast du denn mal die analogen Werte einfach auf die serielle Konsole geschrieben um zu prüfen, ob die auch sinnvolle Werte ausgeben?
Übrigens macht das mapping keinen Sinn, du mapst ja auf den gleichen Wertebereich wie ursprünglich.