Serial Communications help!

Hi everyone,

I'm working on a project. What I want to do is to control the Arduino board using the Serial Monitor. That is when I enter "a", it will do routine A. If entered ''b', it will do routine B.

I can actually do it now, but what I want now is that, for example, If I receive an "a" it will do routine a continuosly, until it reads a "b" on the serial monitor.

How can I do that? Continuosly doing a routine and checking the serial port at the same time? Please give me a sample code.

Thankyou!

you cannot do two things simultaneously (checking serial and doing something else) you have to do them alternatively

it could look like this ...

char command;
void setup()
{
  Serial.begin(115200);
  Serial.println("my first command interpreter :) ");
}

void loop()
{
 if (Serial.available() > 0)
  {  
    command = Serial.read();
  }

  switch(command)
  {
  case 'a' : 
    a(); 
    break;
  case 'b' : 
    b(); 
    break;
  case 'c' : 
    c(); 
    break;
  default:
    Serial.println("unsupported command");
    delay(500);
  }
}

void a()
{
  Serial.println("ape");
  delay(100);
}
void b()
{
  Serial.println("bock");
  delay(100);
}
void c()
{
  Serial.println("cow");
  delay(100);
}