Alla fine vi posto la mia soluzione funzionante:
void loop() {
if (error == 1) { // skip loop if no controller is found, may test adding config_gamepad(pins)
ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, false, false);
return;
}
ps2x.read_gamepad(false, vibrate); //read controller, don't record arrow pressures, and set large motor to spin at 'vibrate' speed
stickX = ps2x.Analog(PSS_LY); // set the analog value of the right stick X-Axis equal (0-255)
stickY = ps2x.Analog(PSS_LX); // set the analog value of the right stick X-Axis equal (0-255)
// MUOVO X-AXIS //
int mapX = stickX; // set the desired stepper position equal to the X-Axis value (0-255)
if (mapX > 123) { // if the X-Axis stick position is positive
motoreX.setSpeed(200);
motoreX.setAcceleration(1);
motoreX.run();
} else if (mapX < 123) { // if the X-Axis stick position is negative
motoreX.setSpeed(-200);
motoreX.setAcceleration(1);
motoreX.run();
} else {
motoreX.stop();
}
// MUOVO Y-AXIS //
int mapY = stickY; // set the desired stepper position equal to the Y-Axis value (0-255)
if (mapY > 123) { // if the Y-Axis stick position is positive
motoreY.setSpeed(200);
motoreY.setAcceleration(1);
motoreY.run();
} else if (mapY < 123) { // if the Y-Axis stick position is negative
motoreY.setSpeed(-200);
motoreY.setAcceleration(1);
motoreY.run();
} else {
motoreY.stop();
}
}