Quote:
|
Originally Posted by stephenthe1
Code:
signed char distance = p1_y - p2_y;
if (distance < 0)
distance = -(distance); //the absolute value of distance
else if (distance <= 14)
{
p1_y = p2_y = (p1_y + p2_y)/2;
}
pwm01 = pwm02 = p1_y;
pwm03 = pwm04 = p2_y;
the only possible problem I can see is how it converts (but doesn't really convert) a signed char to an unsigned char (the pwm values). is this a problem?
|
No, p1_* is unsigned char. The problem may be, though, if the sum of p1_y and p2_y is greater than 255. This would cause wrap around. (eg, 128+128 equals 0).
this would work, though
Code:
p1_y = p2_y = ((long)p1_y + p2_y)/2;