I have an array with 255 quadruples as shown below.
With each iteration of i I want to pass (correct terminology?) the first three values of each quadruple into a function (the three ? in getColourDistance below) in order to return the result of a calculation.
How must this be done in the C++ variant for Arduino?
Thanks!
const int SAMPLES[][4] ={{2223, 1612, 930, 10}, {1855, 814, 530, 20}, {1225, 463, 438, 30}, {1306, 504, 552, 40}, ...};
byte samplesCount = sizeof(SAMPLES) / sizeof(SAMPLES[0]);
for (byte i = 0; i < samplesCount; i++)
{
tcs.getRawData(&r, &g, &b, &c);
colourDistance = getColourDistance(r, g, b, ?, ?, ?);
// do something based on the value of colourDistance
}
int getColourDistance(int sensorR, int sensorG, int sensorB, int sampleR, int sampleG, int sampleB)
{
return sqrt(pow(sensorR - sampleR, 2) + pow(sensorG - sampleG, 2) + pow(sensorB - sampleB, 2));
}
SAMPLES[n][0]gives you the first element of the nth row.SAMPLES[i][0], SAMPLES[i][1], SAMPLES[i][2]if I understand your hint correctly?getColourDistance(r, g, b, SAMPLES[i][0], SAMPLES[i][1], SAMPLES[i][2])