Serial.reading a new Setpoint

Hi,

I'm having trouble setting a new Setpoint in my code using Serial.read.

When I enter 50 via the serial monitor the Setpoint in the code is set to 48. When I enter 52 the Setpoint is 50. So I thought to offset the input of the Setpoint by 2.

When I enter 30 or 90 the Setpoint in the code is 48 also???

For this code to be of any use it is crucial to be able to set the Setpoint, otherwise it will be useless.

Here are the pieces of relevant code (I think). If I need to show the entire code please say so.

int Setpoint = 0;

 if (Serial.available() > 0)      
  {
  Setpoint = (Serial.read());   
  }

I also think the code sometimes stalls after a new Serial read but I'm not sure.

Thanks,

Leo

When you send 50 through serial, it actually sends ascii codes for the 5 and then the 0. That's a 53 for the 5 and then a 48 for the zero.

You're program needs to pick those all up as ascii and convert them to an integer. There are a number of good functions to help do that. Look at atoi and Serial.parseInt.

Hi,

int Setpoint;

  if (Serial.available() > 0)    
  {
  Setpoint = Serial.parseInt();
  }

This seems to work fine!

Thanks again.