added a deadzone to the analogue sticks

This commit is contained in:
2025-05-09 20:24:58 +02:00
parent b90bb4318d
commit 6271671fee
+19 -6
View File
@@ -26,6 +26,9 @@ byte waitTick = 0;
char waitTextOutput[32]; char waitTextOutput[32];
bool isControllerConnected; bool isControllerConnected;
int lx, ly, rx, ry;
int deadzone = 20;
void setup() { void setup() {
Serial.begin(57600); Serial.begin(57600);
delay(300); delay(300);
@@ -46,8 +49,6 @@ void setup() {
void loop() { void loop() {
if (!(error == 0 && type == 0)) { if (!(error == 0 && type == 0)) {
checkControllerConnection(); checkControllerConnection();
delay(50); delay(50);
return; return;
} }
@@ -204,10 +205,22 @@ void loop() {
} }
// Left stick // Left stick
XInput.setJoystick(JOY_LEFT, ps2x.Analog(PSS_LX), 255 - ps2x.Analog(PSS_LY)); lx = ps2x.Analog(PSS_LX) - 128;
ly = 127 - ps2x.Analog(PSS_LY);
if (lx < deadzone && lx > -deadzone && ly < deadzone && ly > -deadzone) {
lx = 0;
ly = 0;
}
XInput.setJoystick(JOY_LEFT, lx, ly);
// Right stick // Right stick
XInput.setJoystick(JOY_RIGHT, ps2x.Analog(PSS_RX), 255 - ps2x.Analog(PSS_RY)); rx = ps2x.Analog(PSS_RX) - 128;
ry = 127 - ps2x.Analog(PSS_RY);
if (rx < deadzone && rx > -deadzone && ry < deadzone && ry > -deadzone) {
rx = 0;
ry = 0;
}
XInput.setJoystick(JOY_RIGHT, rx, ry);
} }
void checkControllerConnection() { void checkControllerConnection() {
@@ -219,8 +232,8 @@ void checkControllerConnection() {
case 0: case 0:
type = ps2x.readType(); type = ps2x.readType();
if (type == 0) { if (type == 0) {
display.write("Found\nDualShock 2!"); display.write("DualShock\n2\nconnected!");
XInput.setJoystickRange(0, 255); XInput.setJoystickRange(-128, 127);
} else { } else {
display.write("Controller\nnot\nrecognised"); display.write("Controller\nnot\nrecognised");
} }