Inverting Y axis on joystick

We need to invert the Y axis and I don’t know how I would code it, any input on this would be great.

All you have to do is subtract your current value from 254. I think you can just do p1_y=254-p1_y; but just to be safe I would use a temp variable. Sooo, temp=254-p1_y; then just use temp instead of p1_y (or whatever joystick port) in your program.

Woulden’t it be temp = 25***5*** - p1_y? Because other wise you can have negative numbers.

If p1_y == 0, then that would evaluate to 255, which is an invalid PWM output. If you’re using an unsigned data type, it can’t be negative, anyway.

Oh, right. But I think the joystick vals go up to 255.

temp = (p1_y == 255) ? 0 : (254 - p1_y);


255 is not a valid output on a PWM. I think 3 consecutive 255’s result in a reset or something.

The range is 0-254, so you want:

p1_y = 254 - p1_y;

No need for a temp variable, the compiler will handle that just fine.

Ok, thank you for correcting me. Though I could’ve sworn I saw 255 on dashboard… :confused: Oh, well :shrug: