So I wrote a code that creates arrays each containing 7 values. I made Arduino read the values from humidity and heat sensors and write them to these arrays hour by hour.
But when I print the values from arrays to the Serial Monitor, I see the seventh integer of humidity array as "19995" and then "-25573", then "-5602" goes like that... Why is it not "0" like others?
And it is always the seventh integer...Very weird.
int heatArray[7] = {0,0,0,0,0,0,0};
int humidityArray[7] = {0,0,0,0,0,0,0};
switch (time) {
case (1): //save the values when launched.
heatArray[1] = heat;
humidityArray[1] = humidity;
break;
case (2): // //save the values after an hour.
heatArray[2] = heat;
humidityArray[2] = humidity;
break;
case (3): // save the values after 2 hours.
heatArray[3] = heat;
humidityArray[3] = nem;
break;
case (4): // save the values after 3 hours.
heatArray[4] = sicaklik;
humidityArray[4] = humidity;
break;
case (5): //save the values after 4 hours.
heatArray[5] = heat;
humidityArray[5] = humidity;
break;
case (6): //save the values after 5 hours.
heatArray[6] = heat;
humidityArray[6] = humidity;
break;
case (7): // save the values after 6 hours.
heatArray[7] = heat;
humidityArray[7] = humidity;
time= 0; // Resets time, starts from beginning.
break;
}
Serial.print("Heat: ");
Serial.print(heatArray[1]);
Serial.print(" ");
Serial.print(heatArray[2]);
Serial.print(" ");
Serial.print(heatArray[3]);
Serial.print(" ");
Serial.print(heatArray[4]);
Serial.print(" ");
Serial.print(heatArray[5]);
Serial.print(" ");
Serial.print(heatArray[6]);
Serial.print(" ");
Serial.println(heatArray[7]);
Serial.println(" ");
Serial.print("Humidity: ");
Serial.print(humidityArray[1]);
Serial.print(" ");
Serial.print(humidityArray[2]);
Serial.print(" ");
Serial.print(humidityArray[3]);
Serial.print(" ");
Serial.print(humidityArray[4]);
Serial.print(" ");
Serial.print(humidityArray[5]);
Serial.print(" ");
Serial.print(humidityArray[6]);
Serial.print(" ");
Serial.print(humidityArray[7]);
Serial.println(" ");
Serial.print("Time passed:");
Serial.println(time);
I omitted unnecessary parts of the code. Please tell me whether I used the Array command right or wrong. What's causing this issue?