Lookup Table in Sketch

hey folks!

I wonder if I can get something in Arduino Duemilanove programming that could help me in making a look up table. I mean, I want to read an analog signal and for every value that is read by Arduino it should correspond to certain constant value. say, for 2v-100, 3v-200,4v-300 etc...

{2,3,4...} -------->{100,200,300...}

is this gettable?
help me..

thnq,
chiru

A simple formula might be a better answer in your situation. You can use a look-up table but, it would not be near as efficient.

x = (y * 100) - 100

Or you could try the "map" function.

Or if the mapping is non linear and you want to interpolate between values you could use multimap() - Arduino Playground - MultiMap -

Or if you don't want to interpollate you can write a gettable() function yourself

int gettable(int in)
{
  if (in == 2) return 100;
  if (in == 3) return 200;
  etc.
  return 0;  // keeps compiler happy ;)
}

which can be made more efficient with an array - see reference section

int table[] = {100,200,300,400,500, ...};

int gettable(int in)
{
  return table[in-2];  // assuming the input values start with 2 ..
}