Need help with code -serial

Here is an approach that you can try.

Create an empty global char array with space for 3 chars (X / Y, 1 / 0, NULL terminate).

char buffer[3];

Try using Serial.readBytes() method described here: Stream.readBytes() - Arduino Reference.

Serial.readBytes(buffer, 2);

Then, use conditional statements to check each char stored in the array, then perform an action based on that.

if(buffer[0] == 'X' && buffer[1] == '1') digitalWrite(pinA, HIGH);

Type "X1", "X0", etc. into the Serial Monitor to send the info.
Note: there is a drop-down menu in the Serial Monitor that says "Newline" or "Carriage Return", etc. Change that to "No Line Ending" first.

Does this help? I never tried it before. It might not be the best method.
Note: this halts your program for 1 second to wait for Serial data. You set that timeout using Serial.setTimeout() method (Stream.setTimeout() - Arduino Reference). I will come up with a different approach later. Have a look at Serial.read crazy results - #20 by system - Programming Questions - Arduino Forum as well.