![]() |
Re: Programming joysticks
If u can make me a favor, can u teach me how to program the joysticks. I will appreciated. thank u
GOOD LUCK THIS YEAR |
Re: Programming joysticks
the inputs from the joysticks are held in a range of variables (actually aliases), set up in ifi_aliases.h:
for instance, the x-axis of joystick one is p1_x if you want direct joystick-to-pwm control, just use something like the following line: pwm01 = p1_x; |
Re: Programming joysticks
Quote:
The value that comes in on these pins is between 0 and 255 (an unsigned char). 0 is full to one side, 127 is center, and 255 is full to the other side. For instance, if you have the joystick all the way forward, p1_x would be 255 and p1_y would be 127. If you had it all the way to the right, p1_y would be 127 and p1_y would be 255. You could also have a combination of the two, of course. For instance, if you where in the forward, right corner, you would get p1_x and p1_y both reading 255. You can use these values in any way in your program. Just don't try to change their value in code; it won't work! Hope that helps. :) Good luck. |
Re: Programming joysticks
Quote:
|
Re: Programming joysticks
Quote:
|
Re: Programming joysticks
Do you know the non-binary values of the pX_wheel in their up- and down positions?
I am trying to use their values with a pwm and do not know what to use. Quote:
|
Re: Programming joysticks
Quote:
If you push the hat up by your code then it will default to the first conditional statement you put in. A more correct way might be to do it this way (using constants provided courtesy of Astronouth7303) Code:
switch (px_wheel & 0xFC) { |
Re: Programming joysticks
Could someone help me out?
What I need is for someone to do out the etc. part of the if( (p1_wheel & 0xC0) == 0xC0 ) { //hat control is pushed right } else if( (p1_wheel & 0xA4) == 0xA4 ) { //hat control is pushed down-left } ... et cetera ... thing so I can do this right. I'm a tad but slow when it comes to binary and hex :( |
Re: Programming joysticks
here they are in binary, decimal, and hex forms...
Neutral: 001011xx 44 0x2C Up Left: 111111xx 252 0xFC Up: 111111xx 252 0xFC Up Right: 111111xx 252 0xFC Left: 011000xx 96 0x60 Right: 110010xx 200 0xCB Down Left: 101001xx 164 0xA4 Down: 100101xx 148 0x94 Down Right: 110101xx 212 0xD4 |
Re: Programming joysticks
Here's a diagram that gives the full range of values and the value to test with AND is bold.
252-255*252-255*252-255 *96-99***44-47**200-203 164-167*148-151*212-215 |
Re: Programming joysticks
Because the last bits are unreliable (from what i've read), how will this affect the program? Should I stick with a general area? example:
Code:
if (p1_wheel >= 42 && p1_wheel <= 46) |
Re: Programming joysticks
your previous code with the bitwise AND (&) should work fine - just use the hex or decimal codes I posted above (because you AND it with the original constant, the lower bits don't matter, and thus it will be true for the entire range).
|
Re: Programming joysticks
at the risk of sounding dumb, how does the AND thing work, and what do I need to do with it?
|
Re: Programming joysticks
Code:
if( (p1_wheel & 0xC0) == 0xC0 )0, 0 = 0 1, 0 = 0 0, 1 = 0 1, 1 = 1 so as you can see, it will only return 1's in the places where both numbers have ones. thus, it will only return all of the bits of one value if the same bits are 1's in the other value. the if statement essentially checks to see that all of the bits that are 1 in 0xC0 are also 1 in p1_wheel. replace 0xC0 with whatever "bitmask" (set of bits) you want to test as being 1. |
Re: Programming joysticks
hey, i have a question
we plugged a motor to the pwn port that corresponds to p1_wheel(the wheel) and teh operator interface shows that when we move the wheel, the values are changing (input), but it is not moving the motor. It is correctly mapped (pwm09 = p1_wheel;) how can i get it to work also, i would like to make code the made a pwm got to speen 255 when p4_sw_trig (trigger) is pushed(equal to 1). my code so far is if (p4_sw_trig == 1) { pwm12 = 255; (for this i commented out pwm12 = p4_wheel;) i also tried p4_wheel = 255; and i tried p4_wheel = 0xFC; } lastly, the y axis dose'nt work on ports 3 and 4 on any joystick i try please help me fix my code, wheels, and y-axes thanx |
| All times are GMT -5. The time now is 05:31. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi