#include #include #include Adafruit_BME280 bme; // I2C // Constants unsigned long myTime; const unsigned long SAMPLING_RATE = 1000; const int MEASUREMENTS_PER_WINDOW = 600; const int WINDOWS_PER_REPORT = 18; // Global variables to compute the 10-minute average float avg_temp = 0; int num_measurements = 0; // Global variables for reporting purposes float averages[WINDOWS_PER_REPORT]; int averages_index; float overall_max = -273.15; // Initialize to lowest possible temperature float overall_min = 1000; // Initialize to highest possible temperature void setup() { Serial.begin(9600); Serial.println(F("BME280 test")); bool status; status = bme.begin(0x76); if (!status) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); while (1); } Serial.println("-- Test --"); Serial.println(); } void loop() { myTime = millis(); float temp = bme.readTemperature(); // Print the current temperature Serial.print("Temperature: "); Serial.print(temp); Serial.println(" *C"); // Check for the overall maximum and minimum temperatures if (temp > overall_max) { overall_max = temp; } if (temp < overall_min) { overall_min = temp; } // Calculate the 10-minute average avg_temp += temp; num_measurements += 1; // If 10 measurements have been taken, calculate the average and store it if (num_measurements == MEASUREMENTS_PER_WINDOW) { avg_temp /= num_measurements; // Store the average in the array averages[averages_index] = avg_temp; averages_index++; // Reset the counters num_measurements = 0; avg_temp = 0; } // If the 'S' character is received, print the summary report if (Serial.available() > 0) { char input = Serial.read(); if (input == 'S') { float overall_avg = 0; for (int i = 0; i < averages_index; i++) { overall_avg += averages[i]; } overall_avg /= averages_index; // Print the summary report Serial.println("Summary Report:"); Serial.print("Overall Average Temperature: "); Serial.print(overall_avg); Serial.println(" *C"); Serial.print("Overall Maximum Temperature: "); Serial.print(max(overall_max, overall_avg)); Serial.println(" *C"); Serial.print("Overall Minimum Temperature: "); Serial.print(min(overall_min, overall_avg)); Serial.println(" *C"); Serial.print("Total Runtime: "); Serial.print(myTime / 1000); Serial.println(" seconds"); Serial.println("Average Temperatures per 10-minute Window:"); for (int i = 0; i < averages_index; i++) { Serial.print("Window "); Serial.print(i + 1); Serial.print(": "); Serial.print(averages[i]); Serial.println(" *C"); } } } delay(SAMPLING_RATE); }