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);
}