Bit of a loop problem

Can you have two “void loop()” in your code?

Trying to blink an led faster than printing to the serial monitor.
Here’s my code:

//variables
float tempC;
float tempF;
int tempPin = 0; // setting LM35 pin to analog 0
int ledPin = 9; // led pin set to digital 9

void setup()
{
  Serial.begin(9600);   //start serial port
  pinMode(ledPin, OUTPUT); // set led pin as output
}

void loop()
{
  tempC = analogRead(tempPin); // read value from sensor
  tempC = (5 * tempC * 100) / 1024; //convert voltage to Celcius
  tempF = (tempC * 9) / 5 + 32;    // convert Celcius to Fahrenheit
  Serial.print(tempF);Serial.println(" F");    // print to serial monitor
  delay(3000);      //wait a few seconds

   {
  if (tempF < 82)  // check tempF
    digitalWrite (ledPin, HIGH); // turn led on
    delay (200) ; //pause
    digitalWrite (ledPin, LOW); //turn led off
    delay(200) ; // pause
   }
    
}

The led blinks at the same rate of “Serial.print”,(delay 3000).
It seems to ignore “(delay 200)” for the led.
Is that because it’s in the same loop?
Tried putting the “if” statement in it’s own “void(loop)”, but I got a
re-definition error.

Can you have two “void loop()” in your code?

I think you answered your own question.

void loop()
{
  tempC = analogRead(tempPin); // read value from sensor
  tempC = (5 * tempC * 100) / 1024; //convert voltage to Celcius
  tempF = (tempC * 9) / 5 + 32;    // convert Celcius to Fahrenheit
  Serial.print(tempF);Serial.println(" F");    // print to serial monitor
  delay(3000);      //wait a few seconds

   [glow]{[/glow]<<<- remove
  if (tempF < 82)  [glow]{[/glow]  <<<put it here//

Oh yes the curly bracket I put in the wrong place, thanks for the help. But the led still blinks at delay(3000), not delay (200). Any more suggestions?

But the led still blinks at delay(3000), not delay (200).

Do you mean that the LED is on for 3 seconds, then off for three seconds, or that it waits 3 seconds to come on, and then goes off 2/10 of a second later?

But the led still blinks at delay(3000), not delay (200).

Upon reaching the end of loop(), the program will start again from the beginning of loop, doing another 3000ms delay. Maybe you need something like this:

if (tempF < 82)  // check tempF
{
    for (byte i=0; i<10; ++i) {
        digitalWrite (ledPin, HIGH); // turn led on
        delay (200) ; //pause
        digitalWrite (ledPin, LOW); //turn led off
        delay(200) ; // pause
    }
}

The second part. It waits 3 seconds to come on.

Upon reaching the end of loop(), the program will start again from the beginning of loop, doing another 3000ms delay.

Ahh, I think I'm beginning to understand. So how do I separate the 2 ? If that's even possible. I want the led to blink at 200, while the serial monitor updates every 3000.

You first get rid of the delay calls. During a call to delay, NOTHING else happens (except that interrupts are processed). Look at the infamous Blink Without Delay example for how to blink an LED without using delay.

Then, expand that concept to have two tests for whether it is time to do something (serial output or light on/off) as well as two variables to hold the time of the last action (serial output or light on/off).

It's really quite simple, once you get the hang of it.

for (byte i=0; i<10; ++i)

That kinda works, I never would of thought of using a ‘For Loop’.

Look at the infamous Blink Without Delay example for how to blink an LED without using delay.

I’ll have to look into that and give a read.
Thanks for the help guys.

Read the blinking with out delay and thought I'd give it a try, but I'm back to blinking at 3000 not 200. http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

//variables
float tempC;
float tempF;
int tempPin = 0; // setting LM35 pin to analog 0
int ledPin = 9; // led pin set to digital 9
int ledState = LOW;
long prevMill = 0;
long interval = 200;



void setup()
{
  Serial.begin(9600);   //start serial port
  pinMode(ledPin, OUTPUT); // set led pin as output
}

void loop()
{
  unsigned long currentMill = millis();
  
  if (currentMill - prevMill > interval) {
    prevMill = currentMill;
    
    
    
    if (ledState == LOW)
      ledState = HIGH;
      else
       ledState = LOW;
     digitalWrite(ledPin,ledState);
     
  
  
  
  tempC = analogRead(tempPin); // read value from sensor
  tempC = (5 * tempC * 100) / 1024; //convert voltage to Celcius
  tempF = (tempC * 9) / 5 + 32;    // convert Celcius to Fahrenheit
  Serial.print(tempF);Serial.println(" F");    // print to serial monitor
  delay(3000);      //wait a few seconds
  
  
  }
        
}

I'm back to blinking at 3000 not 200

delay(3000);      //wait a few seconds

I wonder why.

DOH! :P I totally forgot to put the serial print in it's own non-delay.