I am writing a script where I initialize an array, and then later enter a new set of values into it.
// Setting the sensor color ranges
float blueBounds[3][2] = {{110, 195}, // Blue LED
{34, 124}, // Green LED
{0, 103}}; // Red LED
float redBounds[3][2] = {{33, 158}, // Blue LED
{38, 126}, // Green LED
{126, 174}}; // Red LED
float greenBounds[3][2] = {{64, 143}, // Blue LED
{56, 169}, // Green LED
{13, 99}}; // Red LED
float calibrationSample = 20;
float blueVals[20];
float greenVals[20];
float redVals[20];
float blueSTD;
float greenSTD;
float redSTD;
float blueMin;
float blueMax;
float greenMin;
float greenMax;
float redMin;
float redMax;
// Resetting values
redSum = 0;
greenSum = 0;
blueSum = 0;
redAve = 0;
greenAve = 0;
blueAve = 0;
// Gather data ******************************************************************************************
Serial.println("");
Serial.println("Blue, Green, Red");
for (int i = 0; i <= calibrationSample; i++) {
//*** set LED color to blue ***//
digitalWrite(bluePin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(redPin, HIGH);
delay(delayTime); // wait for photo tranistor to come to steady state
blueVals[i] = analogRead(colorPin); // read phototransistor and store value
blueSum = blueSum + blueVals[i]; // Update the sum
Serial.print(blueVals[i]); Serial.print(", "); // print stored value.
//*** set LED color to green ***//
digitalWrite(bluePin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(redPin, HIGH);
delay(delayTime); // wait for photo tranistor to come to steady state
greenVals[i] = analogRead(colorPin); // read phototransistor and store value
greenSum = greenSum + greenVals[i]; // Update the sum
Serial.print(greenVals[i]); Serial.print(", "); // print stored value.
//*** set LED color to Red ***//
digitalWrite(bluePin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(redPin, LOW);
delay(delayTime); // wait for photo tranistor to come to steady state
redVals[i] = analogRead(colorPin); // read phototransistor and store value
redSum = redSum + redVals[i]; // Update the sum
Serial.println(redVals[i]); // print stored value.
}
// turn off LED and wait for another cycle
digitalWrite(bluePin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(redPin, HIGH);
// Interpret the data *******************************************************************************************
// Calculate the averages
blueAve = blueSum / calibrationSample;
greenAve = greenSum / calibrationSample;
redAve = redSum / calibrationSample;
// Calculate the standard deviations
for(int i = 0; i <= calibrationSample; i++){
blueSTD = blueSTD + sq(blueVals[i] - blueAve);
greenSTD = greenSTD + sq(greenVals[i] - greenAve);
redSTD = redSTD + sq(redVals[i] - redAve);
}
blueSTD = sqrt(blueSTD / calibrationSample);
greenSTD = sqrt(greenSTD / calibrationSample);
redSTD = sqrt(redSTD / calibrationSample);
// Calculate the color ranges
blueMin = blueAve - 3*blueSTD;
blueMax = blueAve + 3*blueSTD;
greenMin = greenAve - 3*greenSTD;
greenMax = greenAve + 3*greenSTD;
redMin = redAve - 3*redSTD;
redMax = redAve + 3*redSTD;
// Set the calibration data
switch(Iteration){
case 0:
blueBounds = {{blueMin, blueMax}, // Blue LED
{greenMin, greenMax}, // Green LED
{redMin, redMax}}; // Red LED
case 1:
greenBounds = {{blueMin, blueMax}, // Blue LED
{greenMin, greenMax}, // Green LED
{redMin, redMax}}; // Red LED
case 2:
redBounds = {{blueMin, blueMax}, // Blue LED
{greenMin, greenMax}, // Green LED
{redMin, redMax}}; // Red LED
}
The color sensor calibration has a default set of values I am using that I then want to edit if I choose to recalibrate the sensor. The problem flags at the end of the script where I enter new values into these arrays giving the error in the title.
I have done some research and I think the problem is that the compiler thinks I am trying to re-initialize the array, but I guess you can't do that?
How do I resolve this issue?