Second bit:
//
// We loop around here whilst ever we have power!
//
void loop()
{
long temp;
// Time to update the time?
if ( updateTime )
UpdateTime();
// Any input to process?
if ( Serial.available() )
HandleTimeSet();
// Has user pressed the reset button
CheckForResetMinMax();
// time to update the temp reading?
if ( ( millis() - lastUpdate ) > UPDATE_INTERVAL )
{
temp = LM35Read();
// Keep min and max values stored in EEPROM
if ( temp < minTemp )
{
minTemp = temp;
EEPROM.write( MIN_TEMP_ADDRESS, minTemp );
}
if ( temp > maxTemp )
{
maxTemp = temp;
EEPROM.write( MAX_TEMP_ADDRESS, maxTemp );
}
lcd.setCursor( 0, 1 );
lcd.print( "T:");
lcd.print( temp );
lcd.write( DEGREE_CHAR ); // custom degree sign
lcd.print( "C " );
lcd.print( "[" );
lcd.print( minTemp );
lcd.write( ARROW_CHAR ); // right facing arrow
lcd.print( maxTemp );
lcd.print( "] " );
lastUpdate = millis();
}
}
//
// Take a reading from the sensor. We actually take multiple and average them.
// The sensor returns a voltage that maps directly to temperature
//
long LM35Read()
{
int ndx;
long adcVal = 0, mV;
animateStart();
for (ndx = 0; ndx < TEMP_SAMPLES; ndx++ )
{
mV = analogRead( TEMP_PIN );
adcVal += mV;
#if ( USE_GROUND_REF )
adcVal -= analogRead( TEMP_REF_PIN );
#endif
delay( INTER_READ_DELAY );
animateStep();
}
animateStop();
// average it
adcVal = (long)( adcVal / TEMP_SAMPLES );
// convert value from ADC steps (0-1023) to mV
mV = adcVal * MV_PER_ADC_STEP;
// now convert mV to degrees C
return( mV / MV_PER_DEGREE ) + LM35Calibration;
}
Note I started implementing a calibration mechanism but haven't completed that yet.