Interpreting serial data to call a function or action

Hi there

I’ve got this 90% working but I think I may have a wrong data type maybe??

Below is the crux of the code where the problem lies. My Arduino Uno receives serial data fine and can echo it back but when I ask it to do a particular function when it receives the number “2” via serial, it doesn’t respond

If I change the code just to respond to any character (not just the character 2) , it runs the function fine

char receivedChar;
boolean newData = false;

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

void loop()
{
recvOneChar();
showNewData();
}

void recvOneChar() {
if (Serial.available() > 0) {
receivedChar = Serial.read();
newData = true;
}
}

void showNewData() {
if (newData == true) {
Serial.print(“This just in >”);
Serial.print(receivedChar);
Serial.println("<");
if ((receivedChar)== 2 ) {
Serial.print(“I GOT A TWO !!”);
// do something else like another function
}
newData = false;
}
}

   if ((receivedChar)== 2)

This will never be true because receivedChar is a character representing a 2, not an integer

Try

if (receivedChar== '2')