Trouble reading Serial input

Hello,

I am trying to use serial input to control a esc for my brushless motor. I used some example code to read the user input data into the serial. When I read this data back though, it keeps reporting 49-58 for all my given inputs of 1-9... any ideas?

Here is a screen shot of what It returns when I input 1, 2, 3, 4, 5 respectively.

#include <Servo.h> 
 
Servo esc;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 10;    // variable to store the servo position 
int serialdata=0;
 
void setup() 
{ 
  Serial.begin(9600);
  
  esc.attach(8);  // attaches the servo on pin 9 to the servo object
  
  esc.write(180);
  delay(50);
  esc.write(0);
  delay(50);
  
} 
 
void loop() 
 
 // send data only when you receive data:
        
        {
          
          int incomingByte=0;
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
    
  int speed_max=serialdata;
  esc.write(speed_max);
  delay(15);
/* for (pos = 0; pos < speed_max; pos ++)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    esc.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  
  for(pos =speed_max; pos>=1; pos--)     // goes from 180 degrees to 0 degrees 
  {                                
    esc.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  */
  
}

Screen shot 2013-09-27 at 11.14.44 PM.png

Look up ASCII table

1 is 49
2 is 50
etc.

Try subtracting 48

                Serial.println(incomingByte, DEC);

You did ask for it in decimal.

Thank you!

Subtracting 48 does work, but what I just found out is I actually want to cast it as a char.

http://forum.arduino.cc/index.php?topic=6666.0

Try making incomingByte char to start with.

Try making incomingByte char to start with.

And give it a meaningful name!

int incomingByte; is so wrong. The variable is not byte-sized. You wouldn't use:
float myInt; or float myChar; or byte myFloat; (I was tempted to use another name here, but it wouldn't have illustrated the point quite the same way :)) would you?