|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||||
|
||||||
|
Re: Programming joysticks
Quote:
|
|
#2
|
||||
|
||||
|
Re: Programming joysticks
Quote:
Code:
if( (p1_wheel & 0xC0) == 0xC0 )
{
//hat control is pushed right
}
else if( (p1_wheel & 0xA4) == 0xA4 )
{
//hat control is pushed down-left
}
...
et cetera
...
Last edited by deltacoder1020 : 02-02-2004 at 12:49. |
|
#3
|
|||
|
|||
|
Re: Programming joysticks
Thanks, that helped a lot. I am just starting out with C so i'm still a little sketchy with it.
|
|
#4
|
||||
|
||||
|
Re: Programming joysticks
no prob. if you want a review on the syntax of C, you could try the various guides in the whitepapers section, or the guide that I'm working on (see the thread in this forum titled "FIRST Programming Tutorial")
|
|
#5
|
||||
|
||||
|
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) {
case Hat_Up_Left: {
// ... Code here
break;
}
case Hat_Up_Right: {
// ... Code here
break;
}
// etc...
default: {
break;
}
}
|
|
#6
|
||||
|
||||
|
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 ![]() |
|
#7
|
||||
|
||||
|
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 Last edited by deltacoder1020 : 16-02-2004 at 00:08. |
|
#8
|
|||
|
|||
|
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 |
|
#9
|
||||
|
||||
|
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)
// I am neutral
if (p1_wheel >= 250 && p1_wheel <= 254)
// I am upperleft;
|
|
#10
|
||||
|
||||
|
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).
|
|
#11
|
||||
|
||||
|
Re: Programming joysticks
at the risk of sounding dumb, how does the AND thing work, and what do I need to do with it?
|
|
#12
|
||||
|
||||
|
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. |
|
#13
|
|||||
|
|||||
|
Re: Programming joysticks
Quote:
|
|
#14
|
||||
|
||||
|
Re: Programming joysticks
Quote:
|
|
#15
|
|||
|
|||
|
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:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Programming Compatition | Angela06 | Programming | 30 | 08-04-2005 23:12 |
| Could use some help with joysticks . . . | archiver | 2001 | 5 | 23-06-2002 23:36 |
| Pneumatics electrical wiring and programming | archiver | 2001 | 1 | 23-06-2002 23:10 |
| Calibrating speed controllers and joysticks | thedillybar | Technical Discussion | 4 | 11-02-2002 13:24 |
| pbasic programming | punarhero | Programming | 4 | 21-01-2002 23:32 |