Last active
August 29, 2015 14:09
-
-
Save BenGriffiths/a40c12b4812eb5e25fe8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() { | |
lcd.setCursor(0,0); | |
lcd.print("Next Upload: "); | |
lcd.setCursor(13,0); | |
lcd.print(timer); lcd.print(" "); | |
if(sinceLastSend <= 0){ | |
sinceLastSend = sendAfter; | |
timer = sendAfter; | |
// Send the data to the server | |
sendData(); | |
}else{ | |
int reading1 = analogRead(therm1); | |
int reading2 = analogRead(therm2); | |
float voltage1 = reading1 * 5.0; voltage1 /= 1024.0; | |
float voltage2 = reading2 * 5.0; voltage2 /= 1024.0; | |
float temperatureC1 = (voltage1 - 0.5) * 100; | |
float temperatureC2 = (voltage2 - 0.5) * 100; | |
// I find that when you use the USB connection instead of | |
// mains power, you might need to remove around 5 degrees | |
// from the final value. | |
float averageTemp = ((temperatureC1 + temperatureC2) / 2); | |
// Perform the smoothing with our array | |
tempTotal= tempTotal - tempReadings[tempIndex]; | |
tempReadings[tempIndex] = averageTemp; | |
tempTotal= tempTotal + tempReadings[tempIndex]; | |
tempIndex = tempIndex + 1; | |
if (tempIndex >= numReadings) { tempIndex = 0; } | |
tempAverage = tempTotal / numReadings; | |
// | |
averageTemp = tempAverage; | |
tempCurrent = averageTemp; | |
lcd.setCursor(0,1); lcd.print("Temp: "); lcd.print(averageTemp); | |
// Update the timer | |
sinceLastSend -= 0.1; | |
if(sinceLastSend < timer){ timer--; } | |
} | |
delay(loopDelay); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment