Serial.available for while ?

Hello there,
I want Serial to be available for a while (1 minute) and if there is no bite incoming go to case 'c'
Can some one help me on this?

Thanks a lot

I want Serial to be available for a while (1 minute)

Why? How long serial data is available depends on how fast it comes in and how fast you read it.

If what you really want is for not more than one minute to go by without reading any serial data, you need to record each time you do read data, and, on every pass through loop() see if it has been more that one minute since you last read.

and if there is no bite incoming go to case 'c'

Out of context, this means nothing.

i add my code. My code is working perfectly. The only thing that i need is to start the ‘c’ loop if no receive incoming bite

unsigned long currentTime; 
unsigned long loopTime;
#define RELAY1  3                                             
#define RELAY2  5                        
#define RELAY3  6
 
void setup()
{    
// Initialise the Arduino data pins for OUTPUT
  pinMode(RELAY1, OUTPUT);       
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);
  currentTime = millis();
  loopTime = currentTime;  
  Serial.begin(9600);
digitalWrite(RELAY3,  HIGH);           
   delay(3000);                                      
   digitalWrite(RELAY3, LOW);
}
 
 void loop(){
if (Serial.available() > 0) {
    int inByte = Serial.read();
    switch (inByte){
 case 'a':
label1:
while(1){ 
  digitalWrite(RELAY3,  HIGH);           
    digitalWrite(RELAY1,  HIGH);           
   delay(300);                                      
   digitalWrite(RELAY1, LOW);          
   delay(500);                                      
        digitalWrite(RELAY2,  HIGH);
    delay(300);                                      
   digitalWrite(RELAY2,  LOW);
    delay(500); 
  Serial.print("currentTime: ");
Serial.println(currentTime);
  delay(100);
  currentTime = millis();
  if(currentTime >= 15000){
  digitalWrite(RELAY1, LOW);
  digitalWrite(RELAY2, LOW);
  digitalWrite(RELAY3, LOW);
    loopTime = currentTime;
while (currentTime  >=1);
exit (1);
}
goto label1;
}
case 'b':
label2:
while(1){
digitalWrite(RELAY3,  HIGH);           
    digitalWrite(RELAY1,  HIGH);           
   delay(300);                                      
   digitalWrite(RELAY1, LOW);          
   delay(500);                                      
        digitalWrite(RELAY2,  HIGH);
    delay(300);                                      
   digitalWrite(RELAY2,  LOW);
    delay(500); 
  Serial.print("currentTime: ");
Serial.println(currentTime);
  delay(100);
  currentTime = millis();
  if(currentTime >= 20000){
  digitalWrite(RELAY1, LOW);
  digitalWrite(RELAY2, LOW);
  digitalWrite(RELAY3, LOW);
    loopTime = currentTime;      
while (currentTime  >=1);
exit (1);
}
goto label2;
}
case 'c':
label3:
while(1){
digitalWrite(RELAY3,  HIGH);           
    digitalWrite(RELAY1,  HIGH);           
   delay(300);                                      
   digitalWrite(RELAY1, LOW);          
   delay(500);                                      
        digitalWrite(RELAY2,  HIGH);
    delay(300);                                      
   digitalWrite(RELAY2,  LOW);
    delay(500); 
  Serial.print("currentTime: ");
Serial.println(currentTime);
  delay(100);
  currentTime = millis();
  if(currentTime >= 25000){
  digitalWrite(RELAY1, LOW);
  digitalWrite(RELAY2, LOW);
  digitalWrite(RELAY3, LOW);
    loopTime = currentTime;      
while (currentTime  >=1);
exit (1);
}
goto label3;
      }
    }
  }
}

So, you want to accept serial data during a minute long interval, and ignore it any other time?

aarg:
So, you want to accept serial data during a minute long interval, and ignore it any other time?

Yes and start case 'c' if pass 1 minute without any bite

  if(currentTime >= 15000){
  digitalWrite(RELAY1, LOW);
  digitalWrite(RELAY2, LOW);
  digitalWrite(RELAY3, LOW);
    loopTime = currentTime;
while (currentTime  >=1);
exit (1);
}

15 seconds after you start the Arduino, it is going to turn into a brick. Why?

goto label1;

Do you have a clue why the function is called loop()? I didn't think so.

I can't even begin to guess what that code is doing. No comments. Infinite while loops. Silly constructs.

PaulS:

  if(currentTime >= 15000){

digitalWrite(RELAY1, LOW);
  digitalWrite(RELAY2, LOW);
  digitalWrite(RELAY3, LOW);
    loopTime = currentTime;
while (currentTime  >=1);
exit (1);
}



15 seconds after you start the Arduino, it is going to turn into a brick. Why? 



goto label1;



Do you have a clue why the function is called loop()? I didn't think so.

I can't even begin to guess what that code is doing. No comments. Infinite while loops. Silly constructs.

Time in my code is just for testing
This program will drive a pool clener with two motors
case 'a' will working for 60 minutes
case 'b' will working for 120 minutes
and case '3' will working for 180 minutes

perhaps now it is clearer for you

pegasakos:
Time in my code is just for testing
This program will drive a pool clener with two motors
case 'a' will working for 60 minutes
case 'b' will working for 120 minutes
and case '3' will working for 180 minutes

perhaps now it is clearer for you

No, it won't. It will get to this line and lock up.

loopTime = currentTime;
while (currentTime  >=1);

If you want to test to figure if there is a specified interval after the last character is received you need something like this code

numBytes = Serial.available();
if (numBytes  > 0) {   
   lastByteMillis = millis();   // data available so reset clock
}
if (millis() - lastByteMillis > = interval) {
   // no data for longer than interval
}

…R