Not recieving multiple values over serial propperly

I'm trying to make an RGB led controller that will work with a program on the pc, and when I'm trying this thing trough the serial console it only gives me a 1 number value like 1, 2 ,5, 6 instead of something like 155. What could be the problem? Please help!

My code:

int redPin = 6;
int greenPin = 5;
int bluePin = 6;

int red = 0;
int green = 0;
int blue = 0;

char kind_of_data;

void setup() {
  
  Serial.begin(9600);
  
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  
}

void loop() {
  while(Serial.available() > 0)
  {
    kind_of_data = Serial.read();
    if(kind_of_data == 'R')Set_Red();
    if(kind_of_data == 'G')Set_Green();
    if(kind_of_data == 'B')Set_Blue();
  }
}

void Set_Red() {
  red = Serial.read()- '0';
  analogWrite(redPin, red);
  Serial.print("Red = ");
  Serial.println(red);
  Serial.print("Green = ");
  Serial.println(green);
  Serial.print("Blue = ");
  Serial.println(blue);
  Serial.println("-----------------------");
  delay(1);
}

void Set_Green() {
  green = Serial.read()- '0';
  analogWrite(greenPin, green);
  Serial.print("Red = ");
  Serial.println(red);
  Serial.print("Green = ");
  Serial.println(green);
  Serial.print("Blue = ");
  Serial.println(blue);
  Serial.println("-----------------------");
  delay(1);
}

void Set_Blue() {
  blue = Serial.read()- '0';
  analogWrite(bluePin, blue);
  Serial.print("Red = ");
  Serial.println(red);
  Serial.print("Green = ");
  Serial.println(green);
  Serial.print("Blue = ");
  Serial.println(blue);
  Serial.println("-----------------------");
  delay(1);
}

The string I put into the console:

R255G50B6

Output form the console:

Red = 2
Green = 0
Blue = 0
-----------------------
Red = 2
Green = 5
Blue = 0
-----------------------
Red = 2
Green = 5
Blue = 3
-----------------------

Please help, and thank you! Sincerely --Valentin

void Set_Red() {
  red = Serial.read()- '0';
  analogWrite(redPin, red);

You are assuming, incorrectly, that there IS something to read. This function gets called when the ‘R’ arrives.

If, by some miracle, the rest of the packet had arrived, the read() call would return the ‘2’.

You REALLY need to read Robin2’s thread on receiving and using serial data. You need to read AND STORE the data as it arrives until the end of the packet arrives. THEN, you can parse the data.

Sending “<R=255,G=128,B=45>” would make it easy to see the packet boundaries, parse the data and use it. Your method does not.

this thread will give you the info you need serial inpu basics Robin2's thread.

Thank you for the link @groundfungus

Building on that, and on @PaulS’s reply it would be even easier if you send <rrr,ggg,bbb> where rrr is the red value, ggg the green value etc. For example <12,123,255>.

If you always send the colour values in the same order the characters R, G and B don’t add any extra information.

…R

Robin2, your thread should be a sticky somewhere if it not already. And I will try to spell it right next time.