Serial Monitor - If Statement issue

Hello friends,

I am in need of some help. I am attempting to change state using the serial monitor. When I input a "1", RaspPidata is getting the ASCII value of "1", which is 49, which is fine. The problem is that I have a global variable named state that is defined as:

int state;

Whenever RaspPidata receives a "1" (or ASCII 49), state is not changing to 0. Same for when it receives a "2" (or ASCII 50), state is not changing to 1.

if (Serial.available()) {
    RaspPidata = Serial.read();
    if (RaspPidata == '49') { //serial write 1
      state = 0; //auto
    }
    if (RaspPidata == '50') { //serial write 2
      state = 1; //man
      //serstate = '50';
    }
    Serial.print("RaspPidata = ");
    Serial.println(RaspPidata);
    Serial.print("state = ");
    Serial.println(state);
  }

I have initialized the global variable state to 1 and 0, with the same result. What exactly am I missing?

Thanks for your help :)

    if (RaspPidata == '49') { //serial write 1

Single quotes are for single characters. Does your keyboard really have a key labeled 49?

Didn't you say that you knew that '0' == 48 and '1' == \49?

   if(RaspPidata == '0')

is better than

   if(RaspPidata == 48)

but both are better than what you are doing.