Quote:
Originally Posted by AmoryG
How did they get those numbers?
|
Are you asking about the inputs to the Limit_Mix() function in the default code?
Code:
pwm13 = pwm14 = Limit_Mix(2000 + p1_y + p1_x - 127);
pwm15 = pwm16 = Limit_Mix(2000 + p1_y - p1_x + 127);
The 2000 is just to force the compiler to use 16-bit arithmetic. Otherwise it would decide that because p1_y, p1_x, and 127 each fit in eight bits, the addition and subtraction should be done with eight bits, and there could be overflows and unexpected results. Limit_Mix() itself subtracts 2000 when it returns the value.
The first line adds the x and y values, correcting the offset so that when both inputs are neutral (127) the sum is also neutral.
The second line does the same thing as the first, but it "mirrors" the x value by subtracting it from 254 first. Then it obscures that step by combining the new +254 and the -127 from the first line into a single +127.