If you want to control the speed of a PWM from a joystick controller then just limiting the final value sent the PWM based on boundaries is a waste. Since 127 is neutral, and you want 200 to be your max, moving your joystick beyond the raw 200 position will do nothing further to the value. You might as well not even limit it.
Instead, try scaling it. Find the difference between your raw value and 127, and divide it by the difference between the the max raw value and 127, then multiply that by the difference between your "new" max and 127.
example: {n = int; d = double}
Code:
nRaw_Value = GetOIAInput (yourport, youraxis);
dFinal_Value_Intermediate = (nRaw_Value - 127) / (maxraw -127);
dFinal_Value_Intermediate = dFinal_Value_Intermediate * (yourmax - 127);
nFinal_Value = dFinal_Value_Intermediate + 127
SetPWM ( yourPWMport, nFinal_Value );
With a joystick on port 1 and the y-axis the numbers would go like this:
Code:
nRaw_Value = GetOIAInput (1, 2);
dFinal_Value_Intermediate = (220 - 127) / (255 - 127);
= 93 / 128;
= 0.7265625;
nFinal_Value_Intermediate = 0.7265625 * (200 -127);
= 0.7265625 * 73;
= 53.0390625;
nFinal_Value = 53 + 127;
= 180;
SetPWM(1, 180);
Of course, there are some casting issues with this example, but you get the idea. I use this technique a lot with my TI-84 Plus calculator graphics.