Sending serial message, received but not following through

I have a code that was sent to me that is supposed to control an LED with serial commands from a computer. I'm using a Teensy 2.0.

When I type "LED 255 \n" into serial monitor and hit send, I get the confirmation that cRead does get LED 255 \n (that's as far as my debugging worked).

When it gets that command, it should light the LED, and Serial.print "BRB". Neither of those things ever happen.

Is the problem with how I'm typing the command into the serial monitor? That part I'm not sure of.

I have tested that the LED works using the blink example, and the button mentioned in the code also works as it should.

Here's the code. I appreciate any help you can provide.

// Arduino Studio settings: Teensy 2.0, Serial, 16 MHz

// Pin assignments.
const int ledPin = PIN_C6;
const int buttonPin = PIN_C7;

// True if the button is up.
bool buttonUp = true;

// Messages received from outside, on the serial port.
const int recvBufferSize = 80;
char recvBuffer[recvBufferSize];
int recvBytes = 0;

void setup()
{
  // Begin serial communication.
  Serial.begin(9600);

  // Receive input from the button.
  pinMode(buttonPin, INPUT);

  // Start by assuming the button is up.
  digitalWrite(buttonPin, HIGH);

  // Shut off the button's LED.
  analogWrite(ledPin, 0);
}

void loop()
{
  // Read the button's state.
  uint8_t uiButtonState = digitalRead(buttonPin);

  // Has the button just been pushed?
  if (uiButtonState == LOW && buttonUp)
  {
    // Let the outside world know that the button was pressed.
    Serial.println("Btn 1");
    Serial.send_now();

    // Remember that the button is down.
    buttonUp = false;
  }

  // Has the button just been released?
  else if (uiButtonState == HIGH && !buttonUp)
  {
    // Let the outside world know that the button was released.
    Serial.println("Btn 0");
    Serial.send_now();

    // Remember that the button is up.
    buttonUp = true;
  }

  // Is there data available on the serial port?
  if (Serial.available() > 0)
  {
    // If the buffer has overflowed, just start over.
    // (All of our commands are short, so this shouldn't
    // happen in normal use.)
    if (recvBytes >= recvBufferSize)
      recvBytes = 0;

    // Save the next byte.
    char cRead = Serial.read();
    recvBuffer[recvBytes++] = cRead;
    Serial.print (cRead);
 
    // If that was a newline, process the request.
    if (cRead == '\n')
    {
      if (recvBytes == 3)
      {
        // "ID" is used to request device-identification.
        if (recvBuffer[0] == 'I' && recvBuffer[1] == 'D')
        {
          // Identify ourselves as a Big Red Button.
          Serial.println("BRB");
        }
      }
      else if (recvBytes == 8)
      {
        char cDigit100 = recvBuffer[4],
          cDigit10 = recvBuffer[5],
          cDigit1 = recvBuffer[6];

        // "LED xxx", where xxx is 000 to 255, is used
        // to set the intensity of the button's LED.
        if (recvBuffer[0] == 'L' && recvBuffer[1] == 'E'
          && recvBuffer[2] == 'D' && recvBuffer[3] == ' '
          && cDigit100 >= '0' && cDigit100 <= '9'
          && cDigit10 >= '0' && cDigit10 <= '9'
          && cDigit1 >= '0' && cDigit1 <= '9')
        {
          int iFade = (cDigit100 - '0') * 100
            + (cDigit10 - '0') * 10
            + (cDigit1 - '0');
          if (iFade >= 0 && iFade <= 255)
          {
            // Set the intensity of the button's LED.
            analogWrite(ledPin, iFade);
          }
        }
      }

      // Prepare to receive another command.
      recvBytes = 0;
    }
  }

  // Don't run at full speed.
  // That probably uses a lot more power.
  delay(5);       
}

The Arduino IDE Serial Monitor sends \r\n by default when you hit the return key. That means that you receive 9 characters instead of 8 as your code expects. Anyway I would make that parser much more tolerant because this behavior changes from terminal emulation to terminal emulation.

    if (cRead == '\n' || cRead == '\r') // Deal with the line feed, too

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

When I type "LED 255 \n" into serial monitor and hit send

The \n that you type is not the '\n' character. It's literally a backslash followed by an n, not the single character.