I have 4 arrays and each has different amount of entries. All these arrays are collected in another one. It's implemented like this:
Code in a c library
static const int32_t ONE_COLOR[2] = { RGB_BLACK, RGB_WHITE };
static const int32_t TWO_COLOR[4] = { RGB_WHITE, RGB_RED, RGB_GREEN, RGB_BLUE };
static const int32_t THREE_COLOR[8] = { RGB_BLACK, RGB_RED, RGB_GREEN, RGB_BLUE,
RGB_CYAN, RGB_YELLOW, RGB_MAGENTA, RGB_WHITE };
static const int32_t FOUR_COLOR[16] = { RGB_WHITE, RGB_RED, RGB_GREEN, RGB_BLUE,
RGB_CYAN, RGB_YELLOW, RGB_MAGENTA, RGB_DARK_RED, RGB_DARK_GREEN,
RGB_DARK_BLUE, RGB_LIGHT_BLUE, RGB_LIGHT_GREEN, RGB_ORANGE, RGB_LIME,
RGB_PINK, RGB_LILA };
static const int32_t* COLOR_ARRAY[4] = { ONE_COLOR, TWO_COLOR, THREE_COLOR,
FOUR_COLOR };
How can I access COLOR_ARRAY[1][2] for example? Thanks for your help :)
Edit Example code for access:
Code for Arduino
for (i = 0; i < colorsLen; i++) {
n = 0;
for (j = 0; j < colorsWrite; j++) {
if (bitArray[i * colorsWrite + j] == 1) {
n |= 1 << (colorsWrite - 1 - j);
}
}
colors[i] = COLOR_ARRAY[colorsWrite - 1][n];
// testing access
// colors[i] = ONE_COLOR[n];
// colors[i] = n;
}
colorsLen
is the length of the array colors
and colorsWrite
is the amount of bits that can be transmitted with one color.
The purpose is to transmit data via light from a smartphone to an arduino and back. To get more bandwith the data is coded with colors. colorsWrite
defines how big colorsLen
should be to get all data transmitted.