Serial Problem

Hi,

I have an issue with my Uno SMD R3 or am I missing something?

I have been prototyping a PC controlled box with Arduino I have hit an issue with the serial communication. I thought it was something in the C# program I had written but have traced it back to the Arduino sketch now if I upload this:

int myValue = 0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  if(Serial.available())
  {
    myValue = Serial.read();
    Serial.flush();
    Serial.println(myValue);
  }
}

if I enter values in the serial monitor, lets say 30, I get an output of 51, 48, 13 and 10! What on earth is going on? I am pretty new to Arduino, this was working the other day and now it's chucking this out.

Any help will be greatly appreciated.

Cheers, Eddie

You're printing the decimal values of the ASCII codes for the characters '3' '0' and new line.

This is a very common noob problem.

If you want to print the characters instead of their integer representation, store the read data in a char, or use Serial.write().

You guys are legends! I can't believe I made such a simple mistake!

Thank you once again, Eddie

Clearly, you haven't read the reference page for Serial.flush().

http://arduino.cc/en/Serial/Flush

Hint: 6th word of the first sentence.

Ironically I had read that, it was just left in from some other part of my program.

Cheers, Eddie