|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Variable Typing
My team wants to subtract 127 from each joystick to change the range from 0 to 255 to -127 to 127. We originally had trouble with this statement:
x_joy_1 = p1_x - 127; // Makes the range -127 to 127 y_joy_1 = p1_y - 127; p1_x is a defined term from the rcdata. x_joy_1 is an int. I'm not precisely sure why we had trouble - I suspect it's because p1_x is of the wrong type (it's a define, not an int). Changing it as one of the team members suggested: int(p1_x) and int(p1_y) resulted in a syntax error. Our final result was this, which works fine: x_joy_1 = p1_x; y_joy_1 = p1_y; x_joy_1 = x_joy_1 - 127; // Makes the range -127 to 127 y_joy_1 = y_joy_1 - 127; printf("x_joy_1 is %d\r\n",x_joy_1); printf("y_joy_1 is %d\r\n",y_joy_1); Could someone shine some light on why this works the way it does? I'm sick of trial and error with variable int types Isn't there a much more elegant way of coding this? |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| disabled typing | Devo1098 | Programming | 2 | 22-03-2007 18:43 |
| variable? | manodrum | Programming | 11 | 01-04-2003 17:20 |
| 26 variable limit | Gusman1188 | Programming | 9 | 12-02-2003 22:38 |
| PBasic Variable | Matt Reiland | Programming | 4 | 15-01-2002 13:16 |