#include int pinRead = 32; int localTime; float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07; unsigned long lastExecutedMillis = 0; float v0 = 3.3; int r1 = 10000.0; double TenMinArr[700] = {0}; double AvgTenMinArr[250] = {0}; int counter = 0, iteration = 0; void setup() { Serial.begin(9600); pinMode(pinRead, INPUT); } void loop() { unsigned long currentMillis = millis(); double tempf, r2, vin; //executed the function once a second if(currentMillis - lastExecutedMillis >= 1000){ String inputStr = Serial.readString(); inputStr.trim(); if(inputStr == "?"){ QueryTenMinAvg(); QueryTenMin(); } lastExecutedMillis = currentMillis; Serial.println(); printTime(); vin = analogRead(pinRead); //formula for converting analog voltage to digital, then voltage into temperature r2 = vin * ((v0) / 256); r2 = r2 * 0.1; tempf = -33.219 * r2 + 160.37; Serial.print("Temp "); Serial.print(tempf); Serial.print(" f "); TenMin(tempf); counter++; } } //Prints out the max, min, and average of all of the values recorded since init void QueryTenMin(){ float highest = 0, lowest = 100, average = 0; for(int k = 0; k < 600; k++){ if(TenMinArr[k] >= highest && TenMinArr[k] != 0){ highest = TenMinArr[k]; } else { Serial.print(" Max: "); Serial.print(highest); break; } } for(int o = 0; o < 600; o++){ if(TenMinArr[o] <= lowest && TenMinArr[o] != 0){ lowest = TenMinArr[o]; } else { Serial.print(" Min: "); Serial.print(lowest); break; } } for(int e = 0; e < 600; e++){ if(TenMinArr[e] != 0){ average = average + TenMinArr[e]; } else { average = average / e; Serial.print(" Avg: "); Serial.print(average); break; } } } //Gives the user the most recent 10 minute average available when a character is entered via serial void QueryTenMinAvg(){ if(AvgTenMinArr[iteration] == 0){ printf("No ten-minute average yet!"); } else { Serial.print("The ten-minute average is: "); Serial.println(AvgTenMinArr[iteration]); } } //collects measurements over course of 10 minutes, stores them in an array void TenMin(double temp){ TenMinArr[counter] = temp; if(counter == 600){ AvgTenMin(); } } //indexes the values of the 10 minute averages in an array void AvgTenMin(){ double compileNum = 0; for(int i = 0; i < 600; i++){ compileNum = compileNum + TenMinArr[i]; } float totalNum = (compileNum / 600); AvgTenMinArr[iteration] = totalNum; TenMinArr[700] = {0}; iteration++; counter = 0; } //prints time since start void printTime() { Serial.print("<"); hourDisplay(); Serial.print(hour()); Serial.print(":"); minuteDisplay(); Serial.print(minute()); Serial.print(":"); secondDisplay(); Serial.print(second()); Serial.print("> "); } //prints hour in time functionality void hourDisplay() { if (hour() < 10) { Serial.print("0"); } } //prints min in time functionality void minuteDisplay() { if (minute() < 10) { Serial.print("0"); } } //prints sec in time functionality void secondDisplay() { if (second() < 10) { Serial.print("0"); } }