const int analogPin = 36; int minValue = 1023; int maxValue = 0; float total = 0; float average = 0; float averages[144]; int averageIndex = 0; unsigned long currentMillis = 0; unsigned long previousTenMinutes = 0; unsigned long previousSecond = 0; // New variable to track the previous second int numReadings = 0; void printAverages() { Serial.println("List of 10-minute averages:"); for (int i = 0; i < averageIndex; i++) { int minutes = (i + 1) * 10; Serial.print("Average "); Serial.print(minutes); Serial.print(" minutes: "); Serial.println(averages[i]); } } void printHighestValue() { Serial.print("Highest value measured: "); Serial.println(maxValue); } void printLowestValue() { Serial.print("Lowest value measured: "); Serial.println(minValue); } void printOverallAverage() { float overallAverage = total / numReadings; Serial.print("Overall average since the start: "); Serial.println(overallAverage); } void setup() { Serial.begin(115200); } void loop() { currentMillis = millis(); int x = analogRead(analogPin); total += x; numReadings++; if (x < minValue) { minValue = x; } if (x > maxValue) { maxValue = x; } if (currentMillis - previousTenMinutes >= 600000) { average = total / numReadings; averages[averageIndex++] = average; total = 0; numReadings = 0; previousTenMinutes = currentMillis; } // Check if one second has passed since the last reading if (currentMillis - previousSecond >= 1000) { // Print the analog pin reading Serial.print("Analog Pin Reading: "); Serial.println(x); previousSecond = currentMillis; // Update the previous second // Check if there is serial input available if (Serial.available() > 0) { char message = Serial.read(); if (message == 'a') { // Print the requested information printAverages(); printHighestValue(); printLowestValue(); printOverallAverage(); delay(3000); } } } }