 # How can I convert a linear changing variable to expo or power function?

The joystick on my wii nunchuck was mapped as 0-127-255, with 127 being the value when centered/rested.

I would like to make it smoother, so maybe I could change this linear movement to something like an odd power function. The following graph tries to convey how the variable would change: Is it posible to do something like this?

If execution time isn't important you could use math functions. If speed matters then a 256 byte lookup table would be a better choice.

Well, a lookup table would be fast, but if memory is important, you might want to consider a function of the form

y = a*(x - 127)^3 . The basic function Y = x^3 has the same shape, so each move of the joystick would create a need to generate an integer cubed (gonna need long integer), followed by (probably) a floating point division to scale it. That may or may not be too time-consuming, depending on your application, and how fast an arduino you want to buy.

My variable changer from 0 to 255, with 127 being the center. I produced a graph in Excel using 0, 127, 255 and some point in between to produce a trendline similar to the behaviour i was looking for. I used the equation of that line to redefine the variable and it worked.

pots=pots+offset1; pots=map(pots,calibration, calibration,0,255); //pots=255-pots;//reversed. pots = floor(0.1 + (6E-05*pow(pots, 3) - 0.0231*pow(pots, 2) + 2.9605*pots + 1.0171)); // apply expo

Imgur

a task for multimap - http://playground.arduino.cc/Main/MultiMap

or it looks approximate like the addition of a sinus on top of y = x; something like

y = x + c * sin( x * (PI / 127.5)); // c to be determined