Problem with reading two digit numbers from serial monitor

Hello. I am getting crazy with this "simple" problem. I am trying to set to variables on my arduino via serial from serial monitor. By sending "a22b28", where "a" is "lowtemp" and "b" is "hightemp". And then printing the result. But when I try it, it only returns the first digit.. so it acts like i write "a2b2".

Any help would be much appreciated.

byte lowtemp = 0;
byte hightemp = 0;

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

  if(Serial.available()){

    switch (byte(Serial.read())){

    case 'a':
      lowtemp = Serial.read();

      break;
      
    case 'b':
      hightemp = Serial.read();

      break;

    }
  }
Serial.println( lowtemp, BYTE );
Serial.println( hightemp, BYTE );

Serial.read() is only going to give you one digit (byte) at a time. You'd need to do something like this:

lowtemp = Serial.read() *10 + Serial.read();

Chris

If the serial.reads occur too quickly in your code, you may miss some because they haven't come in yet. Try this

if(Serial.available() >2 ){  // wait for 3 characters to come in
    switch (byte(Serial.read())){

    case 'a':
      lowtemp_tens = Serial.read() - 0x30;  // convert from ascii to decimal, see asciitable.com
      lowtemp_ones = Serial.read() - 0x30;

lowtemp = lowtemp_tens *10 + lowtemp_ones;
Serial.println( lowtemp, DEC );
      break;
      
    case 'b':
      hightemp_tens = Serial.read() - 0x30;
      hightemp_ones = Serial.read() - 0x30;

hightemp = hightemp_tens*10 + hightemp_ones;
Serial.println( hightemp, DEC );
      break;
    }
  }

Thanks! That did the trick!