#include #include #include TempI2C_LM75 Temperature = TempI2C_LM75(0x48,TempI2C_LM75::nine_bits); float tempErr = 2; unsigned long lastTime = 0; typedef struct tests { float tempCompAVG; unsigned long pastTime; }; tests samples[1440]; int sampleCount = 1; float tempComp1[100]; int compCount = 1; unsigned long startTime; unsigned long myTime; const unsigned long sampleInterval = 600000; float highTemp = 0; float lowTemp = 1000; float averageComp (float tempComp1[1000000], int compCount){ long sum = 0L ; for (int x = 0 ; x < compCount ; x++){ sum += tempComp1[x] ; } return ((float) sum) / compCount; } void setup() { Serial.begin(9600); Serial.println("Start Program!"); startTime = millis(); } void loop() { myTime = millis(); if (myTime - lastTime >= sampleInterval) { //Call the Average function float tempCompAvg = averageComp(tempComp1, compCount); //Reset the counts compCount = 1; int i; while (i=0,i<=1000,i++){ tempComp1[i]=0; } lastTime = millis(); //Storing the variables in the array samples[sampleCount].tempCompAVG = tempCompAvg; samples[sampleCount].pastTime = myTime; sampleCount++; } //Prints out data! String teststr = Serial.readString(); //read until timeout teststr.trim(); //remove any \r \n whitespace at the end of the String if (teststr.equals("report")) // Print temperature data if "report" command is received { for (int i = 0; i <= sampleCount - 1; i++) { Serial.println("Sample " + String(i + 1) + ":"); Serial.println("Temp Computer Avg in Celcius: " + String(samples[i].tempCompAVG)); Serial.println("Highest Temp Registered Overall in Celcius: " + String(highTemp)); Serial.println("Lowest Temp Registered Overall in Celcius: " + String(lowTemp)); Serial.println("Time of Sample in milliseconds: " + String(samples[i].pastTime)); Serial.println(); } Serial.println("AVG TEMPS ONLY!"); for (int i = 0; i <= sampleCount - 1; i++) { Serial.println(samples[i].tempCompAVG); } } else{ tempComp1[compCount] = Temperature.getTemp(); //Checks temp against previous highest and lowest and sets new highest and lowest if (tempComp1[compCount] <= lowTemp){ lowTemp = tempComp1[compCount]; } if (tempComp1[compCount] >= highTemp){ highTemp = tempComp1[compCount]; } compCount++; // Increment compCount by the number of readings taken delayMicroseconds(100); } }