Thanks guys. Here is my code.
I have put the fading led as the continually running code with checking for the temp as a sort of subroutine. It should now continually fade the led in and out while periodically checking for the temperature. Did I get this right?
// LM35 Temperature Sensor and LCD
#include <LCD4Bit.h> // use of LCD4Bit library
//create object to control an LCD.
//number of lines in display=2
LCD4Bit lcd = LCD4Bit(2); // create object to control an LCD # of lines in display=2
int inPin = 5; // select the input pin for analog temp value
int inVal; // integer value for input read from sensor
int i;
int samples[8]; // variables to make a better precision
long interval=4000;
long previousMillis =0;
void setup() {
pinMode(13, OUTPUT); // set LED pin
digitalWrite(13, HIGH); // light the LED
Serial.begin(9600); // set up Serial library at 9600 bps
lcd.init(); // initialize LCD
lcd.printIn("Welcome to my" );
lcd.cursorTo(2, 0); // move cursor to line 2 position 0
lcd.printIn("secret lab");
delay(3000);
}
void loop()
{
for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
{
analogWrite(13, value); // sets the value (range from 0 to 255)
// waits for 30 milli seconds to see the dimming effect
}
for(value = 255; value >=0; value-=5) // fade out (from max to min)
{
analogWrite(13, value);
}
void TempTake()
{
if (millis() - previousMillis > interval) {
previousMillis = millis();
for(i = 0;i<=7;i++){ // gets avg of 8 samples of temperature
samples= ( 5.0 * analogRead(inPin) * 100.0) / 1024.0;
inVal = inVal + samples;
}
inVal = inVal/8.0;
lcd.clear();
char buf[12]; // "-2147483648\0" set buffer for itoa
lcd.printIn(itoa(((inVal * 9)/ 5 + 32), buf, 10));
lcd.printIn(" Fahrenheit");
lcd.cursorTo(2, 0); // move cursor to line 2 position 0
lcd.printIn(itoa((inVal), buf, 10)); // convert to string
lcd.printIn(" Celsius"); lcd.leftScroll(20, 30); // scroll dis 20 chars to left, delaying 30ms each
inVal = 0;
}
}
}