A few beginner problems

Hey, this is my first time on the forum, and I have a couple of questions.
I'm very new to arduino, as well as coding. I got an Arduino Uno SMD for Christmas, as well as an accompanying book. I Have been following the exercises in the book to help start me off.
In this exercise, I am using serial communication to turn an LED on and off by pressing either 1 or 2. This worked fine, and I decided to add in a third command, '3'. This would repeatedly blink the LED on and off. The code compiles and uploads fine, but when I enter 3, the LED blinks on for 100ms, then off and does not loop. I've spent a couple of hours tinkering around but cannot make it work. I came here for some suggestions.

Additionally, I tried to rename the commands for turning the LED on and off, 1 and 2 respectively, "on" and "off", so that when I type on or off in the serial monitor, they will correctly carry out their actions.
When I enter "on" in the serial monitor I get:
Unknown Command: 111
Unknown Command: 110

When I enter "off" I get:
Unknown Command: 111
Unknown Command: 102
Unknown Command: 102

I believe these numbers to be the ASCII for each individual letter, but I can't figure out how to make the code understand it as a single command.
Any help would be appreciated.

Here is a copy of my code

const unsigned int LED_PIN = 13;
const unsigned int BAUD_RATE = 9600;
const unsigned int PAUSE = 100;

void setup() {
	pinMode(LED_PIN, OUTPUT);
	Serial.begin(BAUD_RATE);
}

void loop() {
if (Serial.available() > 0) {
int command = Serial.read();
if (command == 'on') {
digitalWrite(LED_PIN, HIGH);
Serial.println("LED on");
} else if (command == 'off') {
digitalWrite(LED_PIN, LOW);
Serial.println("LED Off");
} else if (command == '3') {
 
  void loop();
 {
    digitalWrite(LED_PIN, HIGH);
    delay (PAUSE);
    digitalWrite (LED_PIN, LOW);
    delay (PAUSE);
  }  
} else {
Serial.print("Unknown Command: ");
Serial.println(command);
}
}
}

Stick to single digits or characters until you've figured out strings, or multi character constants

Thanks for the quick reply, I know what direction to look in now.

Any ideas why I cant get my LED blink to loop?

Looking again, I don't think that code could compile.

I did run you program, it was not working because of command=='on' . I change the code for command=='o' . I modify your code, when you command 3 , it is blinking 3 time... and I notice a loop() within a loop() ... bad programming... anyway I re-write your code and I hope you will understand it.

const unsigned int LED_PIN = 13;
const unsigned int BAUD_RATE = 9600;
const unsigned int PAUSE = 100;
byte command;

void setup()
{
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(BAUD_RATE);
}

void loop()
{
  if (Serial.available() > 0)
  {
      command = Serial.read();
  if (command == 'o')
  {
    digitalWrite(LED_PIN, HIGH);
    Serial.println("LED on");
  }
  else if (command == 'f')
  {
    digitalWrite(LED_PIN, LOW);
    Serial.println("LED Off");
  }
  else if (command == '3') 
  { 
    blink3time(); 
  }  
  else
  {
    Serial.print("Unknown Command: ");
    Serial.println(command);
  }
 }
}

void blink3time()
{
  for (int i=0;i<3;i++)
  { 
    digitalWrite(LED_PIN, HIGH);
    delay (PAUSE);
    digitalWrite (LED_PIN, LOW);
    delay (PAUSE);
  }
}

Looking again, I don't think that code could compile.

AWOL, I did copy and paste the original Op code, to my surprise, it compile... :astonished:

Thanks for the rewrite.
Again, I'm very new to all of this so I'm wondering if I could get some explanations.

Earlier, when you tell the code what to do when you press 3, you call on blink3time
Can you define what "blink3time" does just by writing a separate entry such as this

void blink3time()
{
  for (int i=0;i<3;i++)
  { 
    digitalWrite(LED_PIN, HIGH);
    delay (PAUSE);
    digitalWrite (LED_PIN, LOW);
    delay (PAUSE);
  }
}

And how can I make it continuously loops if I shouldn't call a loop inside a loop.

Also, what is this piece of code telling the program to do?

for (int i=0;i<3;i++)

I think the recursive call to loop threw me

@AWOL

I taugh so to...

@GolfWang

Let me explain :

void blink3time() is call a function. So I name it that way, if you need to blink more time, you just going to the function and change the for() function. The for(int i=0;i<4;i++) is integer i = 0 and start at 0, i++ is i=i+1 i<4 is count if i is lower that 4.

If you want to learn more, in your IDE, click "help" and select "Reference" , most of the key words are there and click on them to find an explanations of the function/statement.

Thank you for the help. I'm going to try to figure out a loop on my own, and will come back if I need help.