Serial Commands to Activate a Digital Output

I am very new to the Arduino and need some direction. I can toggle a digital pin with a single serial character, like a 'T' in the example code below, but I really want to toggle a pin after the serial port reads a series of characters in a row like 'ABCDE'. To clarify, I'd like several actual words to cycle a specific digital pin. Thanks for the help, I really appreciate.

int ledPin = 13; // select the pin for the LED int val = 0; // variable to store the data from the serial port

void setup() { pinMode(ledPin,OUTPUT); // declare the LED's pin as output Serial.begin(19200); // connect to the serial port }

void loop () { // Serial.available() is a way to see if there's serial data // without pausing your code if( Serial.available( ) ) { val = Serial.read(); // read the serial port if( val == 'T') { // if it's an 'T', blink the light digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW);

Where's the problem?

If you plan your instructions then this is quite easy (at a basic level).

E.g. Let's have a command LIGHT which brings a pin high. It takes one parameter which is the number of the pin. So... LIGHT 4 LIGHT 6

If at the end of each command you're transmitting something like a line break then you have something easy to work with. (LIGHT 4\nLIGHT 6\n)

Read from the serial port until you hit a \n (or whatever). Then you have a single statement. Then parse that statement until you hit a space. That gives you the instruction name. We know light only takes one parameter so everything after the space must be the pin number.

To read serial data into an array, until a terminating carriage return:

char inData[20]; // change the size as needed
byte index = 0;
bool ready = false;

void loop()
{
   while(Serial.available() > 0)
   {
      char aChar = Serial.read();
      if(aChar != '\n')
      {
         inData[index] = aChar;
         index++;
         inData[index] = '\0'; // Keep array NULL terminated
      }
      else
      {
          ready = true;
          break; // Skip the rest of the serial data for now
      }
   }

   if(ready)
   {
      // Parse the string

      // Do something with the parse data

      // Now, get ready to do it again
      index = 0;
      inData[index] = '\0';
      ready = false;
   }
}