Just got my arduino. I put together this sketch to turn on an led when I type A into the serial monitor and to turn it off when I type B into the serial monitor. It works great but how do I get it to work with full words. I want to be able to type turnOn13 in the serial monitor instead of just A to get the led to turn on and turnOff13 instead of just B to get it to turn off.
char val; // variable to receive data from the serial port
int ledPin = 13;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(ledPin, OUTPUT);
}
void loop() {
if( Serial.available() ) // if data is available to read
{
val = Serial.read(); // read it and store it in 'val'
Serial.print("I received: ");
Serial.println(val);
}
if( val == 'A' ) digitalWrite(ledPin, HIGH); // turn ON the LED
if( val == 'B' ) digitalWrite(ledPin, LOW); // turn OFF the LED
delay(100); // wait 100ms
}