# Help Understanding 'Autoscale' function

I've got a little problem understanding the "inputVariable" in the Autoscale function found here: http://www.arduino.cc/playground/Main/Autoscale

I want to convert the analog reading from a Wii nunchuck to a range and treat that as a percentage. From what I can tell, the Autoscale will let me do this. It'll take the analog 0-1023 and convert it to -100 to 100, with 0 being the middle. The problem is that I dont understand what the purpose of the inputVariable 'j' is for and how to use it properly.

it looks like you would use it like this: int val = analogRead(pin); int scaledResult = autoScale( 0, 1023, -100, 100, val);

if you want a percent ranging from 0 to 100 you would do this: int val = analogRead(pin); int percent = autoScale( 0, 1023, 0, 100, val);

but to get percents, I just do the following: int val = analogRead(pin); int percent = (val * 10) / 102;

Thanks mem ! As always you've been very helpful.

Hopefully I can get it to work.

Thanks again mem!

Also note that autoScale() has been built into the Arduino core as map(): http://www.arduino.cc/en/Reference/Map