Hallo,
ich habe versucht Pedale zu bauen, die jeweils 1 Achse als Gamecontroller sind.
Da ich deutlich mehr Zeit in meine Programmierkenntnisse investieren hätte sollen,
habe ich laienhaft ein fertiges Script von einem komplexeren Projekt auf YT heruntergeladen und soweit ich konnte gekürzt.
Wenn ich nun versuche die Achsen zu kalibrieren sehe ich Zahlen weit über 100% und es flackert auch, obwohl die Achse smooth bewegt wird.
Das Phänomen tritt auch mit einem Potentiometer anstatt des Hallsensors auf.
Arduino Pro Micro
Hallsensor AH3503
#include <Joystick.h>
// USB Rudder-Pedals
// NOTE: This sketch file is for use with Arduino Leonardo and
// Arduino Micro only.
//------------------------------------------------------------
//change these to define which pins your hall effect sensors or potentiometers are connected.
#define R_PIN A0
#define T_PIN A1
//change these to change trim and limits. Calibrating your joystick in Windows achieves the same thing
#define R_MIN 0
#define R_MAX 1023
#define R_TRIM 0
#define R_INVERT 1
#define T_MIN 0
#define T_MAX 1023
#define T_TRIM 0
#define T_INVERT 1
#include <Joystick.h>
Joystick_ Joystick(0x04,JOYSTICK_TYPE_JOYSTICK,
0, 0, // Button Count, Hat Switch Count
false, false, false, // X and Y, but no Z Axis
false, false, false, // No Rx, Ry, or Rz
true, true, // Yes rudder, yes throttle
false, false, false); // No accelerator, brake, or steering
void setup() {
// Initialize Joystick Library
Joystick.begin(true); //false = dont send automatically. We will sendState() at the end of the loop
Joystick.setRudderRange(-512, 512);
Joystick.setThrottleRange(-512, 512);
}
void loop() {
//read analog axes
int value = map(analogRead(R_PIN) + R_TRIM , R_MIN, R_MAX, -512, 512) * R_INVERT;
Joystick.setRudder(value);
value = map(analogRead(T_PIN) + T_TRIM , T_MIN, T_MAX, -512, 512) * T_INVERT;
Joystick.setThrottle(value);
Joystick.sendState();
delay(5);
}
Hat jemand eine Idee welchen Schritt ich verhaut habe?
Ich stehe mit meinem beschränkten Wissen darüber leider an.
So long,
Rolli