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?
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.
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