Help with look up table

I need help implementing a look up table in one of my projects.

I need to map a pot to an RGB LED, so for each pot position (I have 1024/16 = 64 combinations) I need it to read the 3 PWM values (RGB) to send to the output.

Something like

...
62 {10,0,1}
63 {10,0,0}

Can someone give me some guidance on how to achieve this?

Many Thanks

This should have gone to the programming section. Can I kindly ask the moderators to move it? Much apreciated

casemod:
This should have gone to the programming section. Can I kindly ask the moderators to move it? Much apreciated

I already moved it from the programming section.

Is there any pattern to the data you need? i.e. can it be computed on the fly rather than stored?

Depending which board you are using and what else is going on in your program, the simplest solution would be an ordinary array.

Such as

byte colourValue[64][3]=
  {1,2,2,  //RGB for first colour
   2,1,1,  //RGB for second colour
   //etc 
   //etc
   3,22,1  //RGB for last colour  (dont put a comma on the end)
  };
  
void setup(){}


void loop()
{
int example=17;
  
byte red = colourValue [example][0];
byte green = colourValue[example][0];
byte blue = colourValue[example][0];

}

Although this would be a poor choice if you're short of memory.

Thank you, KenF

Ill have a go and report if I need further help.

By the way does someone know how to create an array in excel with the 3 values?
Manually changing 192 values is a bit tedious.

casemod:
By the way does someone know how to create an array in excel with the 3 values?
Manually changing 192 values is a bit tedious.

Can you give me a clue what the relationship is between those values.

Random.

Its supposed to be used to change the LED colors. I started with a mathematical model, but was ridiculous to make any changes. With a look up table one can choose a range of custom colors.

I only asked as I'm a bit of a guru with excel. It's an excellent tool to build a lookup table.

Just put in your first row of values
put in a formula below to get the next value
Then highlight your second row and drag the right hand corner down to complete the table
Highlight all the columns in your table
Format.. Cells.. Custom...
put the type as ##","
Then highlight your table
Copy
Go into the IDE and paste
Finally remove the last redundant comma.

It would probably be better if you convert the RGB values to 565 format for the array (3 bytes vs one int = less memory), then when you want to use the values, you just convert them back to RGB.

ADV: save some memory
DIS: lose precision on the way back

KenF:
I only asked as I'm a bit of a guru with excel. It's an excellent tool to build a lookup table.

Just put in your first row of values
put in a formula below to get the next value
Then highlight your second row and drag the right hand corner down to complete the table
Highlight all the columns in your table
Format.. Cells.. Custom...
put the type as ##","
Then highlight your table
Copy
Go into the IDE and paste
Finally remove the last redundant comma.

I wasn't aware you could actually do it with a comma, that simplifies the process a lot, thanks

One last question:

I would like to add an extra "tab" to the program to keep the look up table, but apparently I need to include it somehow.

I know how I can add it as an external file but not to the tabs on the arduino ide itself. Any ideas?

Regards

pot1212.jpg

Easy.
Make the new tab and add .h on the name. Ex myArray.h
Add your array and also include Arduino.h.

In your main sketch include the new tab #include "myArray.h"
Save both and compile.