Hello, I need a little help getting my joystick to work correctly on my pro micro. I'll be using the device as a gamepad and have no issues with anything other than the analog joystick. I'm using the joystick library and the relevant code I'm using is called during the loop method and is as follows:
xAxis_ = analogRead(A0);
//If our value is less than the low end of the deadzone (480) and above our lowest acceptable value (200) map it accordingly between -127 and 0
if (xAxis_ < 480 && xAxis_ >= 200) {
xAxis_ = map(xAxis_,200,480,-127,0);
} else if (xAxis_ > 520 && xAxis_ <= 800) { //If our value is greater than the high end of the deadzone (520) and below our highest acceptable value (800) map it accordingly between 0 and 127
xAxis_ = map(xAxis_,520,800,0,127);
} else if (xAxis_ > 800){ //If our value is above 800 bring it back to 800
xAxis_ = 800;
xAxis_ = map(xAxis_,200,800,-127,127);
} else if (xAxis_ < 200) { //If our value is below our min value of 200 set it to 200
xAxis_ = 200;
xAxis_ = map(xAxis_,200,800,-127,127);
} else { //If the code makes it here our value fell between our deadzone of 480 and 520 and thus will be set to 0
xAxis_ = 0;
}
Serial.println(xAxis_);
Joystick.setXAxis(xAxis_);
//Same as above but for y axis
yAxis_ = analogRead(A1);
if (yAxis_ < 480 && yAxis_ >= 200) {
yAxis_ = map(yAxis_,200,480,-127,0);
} else if (yAxis_ > 520 && yAxis_ <= 800) {
yAxis_ = map(yAxis_,520,800,0,127);
} else if (yAxis_ > 800){
yAxis_ = 800;
yAxis_ = map(yAxis_,200,800,-127,127);
} else if (yAxis_ < 200) {
yAxis_ = 200;
yAxis_ = map(yAxis_,200,800,-127,127);
} else {
yAxis_ = 0;
}
Serial.println(yAxis_);
Joystick.setYAxis(yAxis_);
So while looking in the serial monitor this code works perfectly and exactly as expected. The issue comes when I test it in windows or another program. For example, while looking at the properties in windows and while the joystick is in a neutral position, the indicator is showing that the joystick is up and to the left.
I've also attempted to use this on my raspberry pi running retro pi and was getting a constant up or left press from the analog stick.
I saw from a post somewhere that windows expects the X/Y values of the stick to fall between -127 and 127 so that's why I convert my values to fit on that scale. Is this true? Am I missing something?
Any help would be greatly appreciated. Thank you in advance!