Quote:
|
Originally Posted by Joel J.
Are you overflowing?
Does p1_y go from -128 to 127, or from 0 to 255.
If its from 0 to 255, then adding 127 definitely takes you out of the range of an unsigned char.
If its from -128 to 127, then it seems that saving (127+127) to a signed char would also result in overflow.
If you want to scale by 75% you can multiply by three, then divide by four:
p1_y = 3*(p1_y + 127)/4;
No need for floats.
|
Well the first line of the code works ok I believe. p1_y from the steering wheel goes from around 60 to 150 or something like that. The correction fixes it ok. If I change the if statement to, say, 254, the code will work correctly until 254 then flop to 1. If I change the if statement to 145, the code will work correctly until 145 then flop to 1. So I am deducing that my assignment in the if block is causing the headache. That being said, I am going to try what you suggested, because once things over range, all logic can be thrown out the window!
