View Full Version : Inverting Y axis on joystick
FormatteD_C
24-02-2004, 16:22
Hey,
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.
Astronouth7303
24-02-2004, 16:40
Woulden't it be temp = 255 - p1_y? Because other wise you can have negative numbers.
FotoPlasma
24-02-2004, 16:42
Woulden't it be temp = 255 - 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.
Astronouth7303
24-02-2004, 16:47
Oh, right. But I think the joystick vals go up to 255.
deltacoder1020
24-02-2004, 16:51
temp = (p1_y == 255) ? 0 : (254 - p1_y); :)
jeremy562
24-02-2004, 16:52
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.
Astronouth7303
24-02-2004, 16:56
Ok, thank you for correcting me. Though I could've sworn I saw 255 on dashboard... :confused: Oh, well :shrug:
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.