#include //Defining Variables //Used short instead of int because takes up less space short temp, min10 = 0, i = 0, c = 0, max1 = -200, min1 = 200; short avrg10[144]; int final1 = 0, num = 0; //Initializes A0-A2 pins on the chip of the temperature sensor LM75A lm75a_sensor(false,false,false); //Every ten minutes compute average and return the iteration int every_ten(int i, short min10, short avrg10[], int num) { if(num%600 == 0) { avrg10[i] = min10/600; i++; } return i; } //Print the overall report of the temperature data void report (int num, short avrg10[], int final1, short max1, short min1) { Serial.println("The Average Temperature in the room every 10 min1utes in Celsius is: "); //Prints out the average for every 10 minute iteration for (i = 0; i < num/600; i++) { Serial.println(avrg10[i]); } Serial.println(); //Prints out the highest temperature recorded Serial.println("Highest Temperature: "); Serial.println(max1); Serial.println(" degrees"); //Prints out the lowest temperature recorded Serial.println("Lowest Temperature: "); Serial.println(min1); Serial.println(" degrees"); //Prints out the overall average recorded Serial.println(); Serial.print("Overall Average: "); Serial.print(final1/num); Serial.println(" degrees"); } void setup() { // put your setup code here, to run once: Serial.begin(115200); //Tells you when the code begins and how to get a report delay(400); Serial.println("The program is beggining. When the program is running press r to receive a report:"); } void loop() { // put your main code here, to run repeatedly: //Collects the temperature and assigns it to the temp variable temp = lm75a_sensor.getTemperatureInDegrees(); //If there is a new max replace the old one if (temp > max1) { max1 = temp; } //If there is a new min replace the old one if(temp < min1) { min1 = temp; } //Prints the current temperature Serial.print("Current Temperature: "); Serial.print(temp); Serial.println(" degrees"); //Add the temperature to variables so that it can be averaged later min10 += temp; final1 += temp; //The number of counts that will be used to find the average num++; //Happens every 10 miniutes i = every_ten(i, min10, avrg10, num); //Resets the variable used for the ten minute average if (num%600 == 0) { min10 = 0; } //Detects if the user has typed r and prints the report if they do if (Serial.available() > 0) { if(Serial.read() == 'r') { report(num, avrg10, final1, max1, min1); } } //Delay a millisecond because the code takes less than a millisecond delay(1); while (millis()%1000 != 0); while(num == 86400) { if(c == 0) { Serial.println(); Serial.println("The program has been running for 24 hours! It will now end."); Serial.println("Press r to print the report"); c++; } if(Serial.available() > 0) { if(Serial.read() == 'r'); report(num, avrg10, final1, max1, min1); } } }