Hello,
Having a bit of trouble with getting a usable signal out of a wired xbox controller while using the USB_Host_Shield_2.0 and XBOXOLD.h libraries.
The controller is connecting properly and is being used to drive a pwm shield in a mapped output for the hats. Below is the relevant bit of code mapping the left hat in the X axis.
The objective is to have 0% output when the stick is at it's neutral position, and 100% output to either channel of the pwm when the stick is moved to either side on the x axis.
The problem is that the output is not behaving as it should, as the controller signal is jittery and bouncing all around. Any tips as to what's happening?
Also uncertain that between 7500 and -7500 is the deadzone on the controller.
Cheers.
Usb.Task();
if (Xbox.XboxConnected) {
if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500) {
if (Xbox.getAnalogHat(LeftHatX) > 7500) {
val_LHXposMap = map(Xbox.getAnalogHat(LeftHatX), 7500, 32767, 0, 4095);
pwm.setPWM(0, 0, val_LHXposMap);
Serial.print(F("LeftHatX+: "));
Serial.print(val_LHXposMap);
Serial.print("\t");
}
if (Xbox.getAnalogHat(LeftHatX) < -7500) {
val_LHXnegMap = map(Xbox.getAnalogHat(LeftHatX), -7500, -32767, 0, 4095);
pwm.setPWM(1, 0, val_LHXnegMap);
Serial.print(F("LeftHatX-: "));
Serial.print(val_LHXnegMap);
Serial.print("\t");
}