Help with Multiple Inputs

Hi! As you can probably guess I am a noob and am trying to learn arduino with close to no programming experience. I am trying to use the virtual serial monitor to recieve multiple inputs from one message. I HAVE googled this but being the noob I am I can't seem to gain anything from what I have read.

My project is basically just trying to get my arduino to ask for three values(Red, Green, Blue) and then use those values to create colors on my RGB led. My led is wired correctly as I have tested it with other programs from the net just to see if it worked.

The code I semi-made semi-stole is below. Please help!

int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int Red = 0;
int Green = 0;
int Blue = 0;

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

void loop()
{
  if (Serial.available())
  {
     Serial.print("Red Value?");
     Serial.println(" ");
     delay(2000);
     int Red = Serial.read();
     Serial.print("Green Value?");
     Serial.println(" ");
     int Green = Serial.read();
     delay(2000);
     Serial.print("Blue Value?");
     Serial.println(" ");
     int Blue = Serial.read();
     setColor(Red, Green, Blue);
     delay(2000);
   }
  else
  {
   setColor(Red, Green, Blue);
  }
}

void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}

Many thanks and have a good day.

I had a lot of free time today.

You had some errors on the code, it’s not neccesary to redefine the variables Red, Green and Blue as an integer again because you did it on the beginning of the code. And to read strings into integers you must use the function parseInt(). I didn’t check if the function SetColor is correct but the compiler didn’t throw any error.

I hope this works, it compiles but is not tested. Good luck.

int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int Red = 0;
int Green = 0;
int Blue = 0;
 
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
}
 
void loop()
{
Serial.println("Red Value?");

while(Serial.available()<1){}  //wait 'til enter number
Red=Serial.parseInt(); //neccesary to transform the input string to an integer

Serial.println("Green Value?");

while(Serial.available()<1){}
Green=Serial.parseInt();

Serial.println("Blue Value?");

while(Serial.available()<1){}
Blue=Serial.parseInt();

setColor(Red, Green, Blue);
delay(2000);
}
 
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}

Thank you so much Mart256 :D I ran it and it works great! This will most definitely help me out further along the way! I hope rewriting my poorly written code was not too time consuming ;)

Thanks again!

Your welcome.I just spent couple of minutes don’t worry. When you get the experience you’ll code faster.