PDA

View Full Version : Inverting numbers



Picstar
- 2nd January 2011, 13:19
Hello all,
I my most recent project I need an algorithm that will convert low numbers into high ones and vice versa. For instance, I need 255 to be 0, or 1, and 2 to be 255. Im reading these numbers from a pot and need to reverse them to get an accurate speed readout. Any ideas? Thanks for reading. Happy New Year!

HenrikOlsson
- 2nd January 2011, 13:31
Hi,

myValue VAR BYTE
myValue = 255 - myValue
Now, if myValue is 0 you'll get 255, if myValue is 255, you'll get 0.

/Henrik.

Picstar
- 2nd January 2011, 14:17
Thanks Henrik, I guess I shouldn't have slept through math class. Your the man!.

muddy0409
- 3rd January 2011, 13:36
Why don't you reverse the connections to the pot?
/