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();
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.