 # using a look up table

Hi folks,

I have a potentiometer that controls a few things and right now I use a few mathematical equations to get the resulting action. Rather I would like to implement a look up table and have every of the 256 values mapped to do something. Say 0 to 30, turn on LED1, 30-60, LED 2.... {Just an example}

Any ideas or code examples to achieve this?

Use the bits in an 8 bit number to signify something. bit one= turn on LED 1, bit 2 = turn on LED 2...

Then create the 256 byte array:

``````action = {1,1,1,2,2,2,3,3,...}
``````

depending on what action. Then use bitTest() to tell what action needs to be taken.

The values are completely random, hence the need for a look up table ;)

if the distances are equal you could do

``````int raw = analogRead(A0);

int action = (raw * 30)/1023; //  or raw/34

switch(action)
{
case 0: ...
etc
``````

of the distances are not equal you could code the maxvalue per "section";

``````int sections[] = { 10, 20, 30, 40, 50, 200, 900, 1023 };  //0..10, 11..20, 21..30 etc