Pro Micro thumbstick Looping, Why?

Hi All,
I followed an instructable attaching a thumbstick to a pro-Micro. I used IDE 1.0.5 and I get response when testing in Joy.cpl. But, The joystick is looping.

For example: if I push up on the thumbstick the + will move upward. As I continue to move the thumbstick up to it’s full extent, the + loops to the bottom, so now I’m going ‘down’ while the stick is pointing up.

I have the same problem with the Y axis. I have a feeling that the problem is in the .ino file (attached), but I can’t be sure. Any help would be appreciated… Thanks :slight_smile:

(http://www.instructables.com/id/Add-a-little-two-analog-axis-thumb-joystick-to-you/?ALLSTEPS)

thumbstick.ino (939 Bytes)

Why don't you just post the code?

ThumbState_t thumbSt;

const bool DEBUG = false; // set to true to debug the raw values

int xPin = A2;
int yPin = A3;
int xZero, yZero;
int xValue, yValue;
int deadzone = 5; // smaller values will be set to 0

void setup(){
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);

if(DEBUG) {
Serial.begin(9600);
}

// calculate neutral position
xZero = analogRead(xPin);
yZero = analogRead(yPin);

thumbSt.xAxis = 0;
thumbSt.yAxis = 0;
}

void loop(){
xValue = analogRead(xPin) - xZero;
yValue = analogRead(yPin) - yZero;

if(abs(xValue) < deadzone) {
xValue = 0;
}
if(abs(yValue) < deadzone) {
yValue = 0;
}

thumbSt.xAxis = map(xValue, 400, -400, -32768, 32768); // here the axis is inverted
thumbSt.yAxis = map(yValue, -400, 400, -32768, 32768);

if(DEBUG) {
Serial.print("X: ");
Serial.println(xValue);
Serial.print("Y: ");
Serial.println(yValue);
}

// Send to USB
Thumbstick.setState(&thumbSt);
}

I suppose I asked for that. :(

if I push up on the thumbstick the + will move upward. As I continue to move the thumbstick up to it's full extent, the + loops to the bottom, so now I'm going 'down' while the stick is pointing up.

Print the values to the monitor. What do you see?

LarryD: Print the values to the monitor. What do you see?

Sorry, I'm new to Arduino. How do I do this?

Make DEBUG = true;

Got it. I get Max values:

X 490, -529 y 519, -502

I'm guessing that I should put these in here?:

thumbSt.xAxis = map(xValue, 400, -400, -32768, 32768); thumbSt.yAxis = map(yValue, -400, 400, -32768, 32768);

See: https://www.arduino.cc/en/Reference/Map

If you are seeing X 490, -529 y 519, -502

Try: thumbSt.xAxis = map(xValue, 490, -529, -32768, 32768); etc.

That did it!

Thanks!

You may want to add some to the numbers to make sure you do not over/under shoot. .