#include #include #include TempI2C_LM75 termo = TempI2C_LM75(0x48, TempI2C_LM75::nine_bits); unsigned long start_time = 0; // Variable to store the start time unsigned long last_measurement_time = 0; // Variable to store the time of the last measurement unsigned int measurement_count = 0; // Variable to track the number of measurements double sum_measurements = 0; // Variable to store the sum of all measurements double highest_value = 0; // Variable to store the highest value double lowest_value = 0; // Variable to store the lowest value double ten_minute_average = 0; //Variable to store ten minute averages double overall_average = 0; //Variable to store overall average double ten_minute_count = 0; //variable for help calculating overall average const unsigned long ten_minutes = 10 * 60 * 1000; // 10 minutes in milliseconds //Setting Up void setup() { Serial.begin(115200); Serial.println("Start"); Serial.print("Actual temp "); Serial.print(termo.getTemp()); Serial.println(" oC"); delay(2000); start_time = millis(); // Store the start time last_measurement_time = start_time; // Set the last measurement time as the start time } void loop() { unsigned long current_time = millis(); // Get the current time // Perform measurement every 5 seconds if (current_time - last_measurement_time >= 5000) { double measurement = termo.getTemp(); // Get the temperature measurement // Update max and mins measurement_count++; sum_measurements += measurement; // Update highest and lowest values if (measurement > highest_value) { highest_value = measurement; } if (measurement < lowest_value || lowest_value == 0) { lowest_value = measurement; } // Print the current temperature Serial.print(measurement); Serial.println(" degrees C"); last_measurement_time = current_time; // Update the last measurement time } // Calculate and print statistics every 10 minutes if (current_time - start_time >= ten_minutes) { // Calculate statistics ten_minute_count++; ten_minute_average = sum_measurements / measurement_count; overall_average += ten_minute_average; if (ten_minute_count != 1) overall_average /= 2; // Print statistics Serial.println("-------- Statistics --------"); Serial.print("10-Minute Average: "); Serial.println(ten_minute_average); Serial.print("Overall Average: "); Serial.println(overall_average); Serial.print("Highest Value: "); Serial.println(highest_value); Serial.print("Lowest Value: "); Serial.println(lowest_value); Serial.println(); // Reset statistics variables start_time = current_time; measurement_count = 0; sum_measurements = 0; highest_value = 0; lowest_value = 0; } }