Question about Arduino Serial

#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3
 
#define FADESPEED 5     // make this higher to slow down

void setup() {
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  Serial.begin(9600);
  Serial.println("Starting Program....");
  start();
  
}

  int g = 0;

char val = 0;
String valstr = "";
      
 void loop(){  
      if(Serial.available() > 0){
      val = Serial.read();
      
       if(val != '\n'){
      valstr += val;
       }
       else{
        Serial.println(valstr);

        if (valstr != "Yes"){
          valstr = "";
        start();
                }
                else{
                  Serial.print("Now Asking for RGB values: \n");
                  Serial.println("What is green value: ");
                 green();
               //
               //
                valstr = "";
            //    start();   
                }
      valstr = "";
//    green();

     }
      }
 }
 
 
      

void start(){
  Serial.print("Do you want a new color? Enter Yes/No:  ");  
}

  
 char gbyte = 0;
 String gstr = "";
 boolean not_number;
 
 int gnum = 256;
  

void green(){

    if(Serial.available() > 0)
      gbyte = Serial.read();

      if ((gbyte >= '0') && (gbyte <= '9')) {
      gstr += gbyte;
      }
    else if(gbyte == ' '){
      Serial.println("This is not a number! \n");
      Serial.println("Enter a valid number!");
      gstr = "";
      
      gbyte = Serial.read();
      
      
    }
    else{
      Serial.println(gstr);
      Serial.println("This is a number");
      
    }
      
      gstr += gbyte;

 //     gnum = gstr.toInt();

 //     if((gnum >= 0) && (gnum <= 255))

So right now that is my code, It is trying to read the different RGB Values for my LED Strip

However, When I get to where I ask for the green value, there is an unknown byte going through and it automatically goes straight to the else part in green();

I didn't input anything yet but Serial says there is something there. What is it?

Please read #7 below:

http://forum.arduino.cc/index.php/topic,148850.0.html

Does anyone know?

The code as you posted it, doesn't compile.

Are you using the Serial Monitor to send characters? Did you remember to change the "Line Ending" dropdown to Newline only?

You'd make your life a lost easier if you dropped using strings. A single character would be much easier to process. When getting digits, multiplying by 10 allows to receive multiple digits.

Have a look at the examples in Serial Input Basics. There is also a parse example to convert received characters into numbers.

...R