Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Inverting Y axis on joystick (http://www.chiefdelphi.com/forums/showthread.php?t=25963)

FormatteD_C 24-02-2004 16:22

Inverting Y axis on joystick
 
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.

JoshJ 24-02-2004 16:25

Re: Inverting Y axis on joystick
 
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

Re: Inverting Y axis on joystick
 
Woulden't it be temp = 255 - p1_y? Because other wise you can have negative numbers.

FotoPlasma 24-02-2004 16:42

Re: Inverting Y axis on joystick
 
Quote:

Originally Posted by Astronouth7303
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

Re: Inverting Y axis on joystick
 
Oh, right. But I think the joystick vals go up to 255.

deltacoder1020 24-02-2004 16:51

Re: Inverting Y axis on joystick
 
Code:


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

:)

jeremy562 24-02-2004 16:52

Re: Inverting Y axis on joystick
 
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

Re: Inverting Y axis on joystick
 
Ok, thank you for correcting me. Though I could've sworn I saw 255 on dashboard... :confused: Oh, well :shrug:


All times are GMT -5. The time now is 20:46.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi