serial print?

Hi everyone,

I'm programming the arduino mega to control some motor controllers with serial outputs. I was doing a test with Serial.print() function, but I have some problems with it. My loop function:

void loop()
{
  if(Serial.available()>0)
  {
    speed1 = Serial.read();
    Serial.print(speed1);
  }
  Serial.flush();
}

speed1 is a int for some reason, the serial monitor never shows what I type in. for example, i type in 78, but the serial monitor either shows 55 or 10. am I doing something wrong? I feel like that it is not receiving my commands as it is, but as an ASCII code.

Thank You

Simple serial test code.

// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

String readString;

void setup() {
    Serial.begin(9600);
        Serial.println("serial test 0021"); // so I can keep track of what is loaded
        }

void loop() {

        while (Serial.available()) {
        delay(10);  
      if (Serial.available() >0) {
        char c = Serial.read();
        readString += c;}
        }
        
      if (readString.length() >0) {
      Serial.println(readString);
      
      readString="";
      } 
   }

for some reason, the serial monitor never shows what I type in. for example, i type in 78, but the serial monitor either shows 55 or 10.

Your code is functioning perfectly. 55 (0x37) is the ASCII code for the digit '7'.

10 is the ASCII code for line-feed.

What are you using to enter the values? zoomkat's code may not work if you are not using the IDE's serial monitor.