Hello, I'm starting at the fantastic world of Arduino.
Today I was trying to do my Arduino to communicate through the serial port with the code below:
byte red;
byte green;
byte blue;
int p_red = 9;
int p_green = 10;
int p_blue = 11;void setup()
{
Serial.begin(9600);
Serial.flush();
pinMode(p_red,OUTPUT);
pinMode(p_green,OUTPUT);
pinMode(p_blue,OUTPUT);
}void loop()
{
Serial.print("Entre com o valor R: ");
red = Serial.read();
delay(5000);
Serial.print("Entre com o valor G: ");
green = Serial.read();
delay(5000);
Serial.println("Entre com o valor B: ");
blue = Serial.read();
delay(5000);
Serial.print("R ");
Serial.println(red);
Serial.print("G ");
Serial.println(green);
Serial.print("B ");
Serial.println(blue);
analogWrite(p_red,red);
analogWrite(p_green,green);
analogWrite(p_blue,blue);
delay(5000);
}
I wish my Arduino expected I give the answer by the computer before proceeding to the next line, you can do this?
Thanks!