Have a problem about the if-else sentence

The function blink() requires the int blinkdelay. However , the blinkdelay comes from serial communication.What if there is no message in the serial channel?How will the blink() work then?Will the program stop at the Serial.available() untill there is message in the serial channel? Thank you so much for answering

int blinkdelay;
const int ledPin = 13;
char message[6];
int index = 0;

void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
if(Serial.available())
{if(index<5 ){
message[index++] = Serial.read();
}
else
{ message[index] = 0;
blinkdelay = atoi(message) ;
index = 0;
}
blink();

}
}

void blink()
{
digitalWrite(ledPin, HIGH);
delay(blinkdelay/2);
digitalWrite(ledPin, LOW);
delay(blinkdelay/2);
}

No it will not stop. The if statement will be evaluated as false, then check for an else statement (which doesn't exist) and then move on.

adwsystems:
No it will not stop. The if statement will be evaluated as false, then check for an else statement (which doesn't exist) and then move on.

Thanks a lot.But the program will run function blink(),right?
However, there is no blinkdelay. How will the blink()run?

Sure there is a blinkdelay. It's just zero until you get a new value to set it to. You should probably give it some value when you create it.

If the formatting was cleaner (each {} on its own line, or try the auto-format in the IDE, it would be easier to see the blink() call is inside the Serial.available() if statement. Nothing available, no blink.

void loop()
 {
  if(Serial.available())
   {
    if(index<5 )
     {
      message[index++] = Serial.read();
     }
     else
      {
       message[index] = 0;
       blinkdelay =  atoi(message) ;
       index = 0;
      }
    blink();
   }
 }