I have been learning the Arduino for almost a whole week. I'm using the UNO. I plan on using the Teensy LC, and hence am using IDE 1.8.12.
I am trying to implement a tutorial program essentially copied from an on-line source. Other than changing a few names, the code is exactally as in the tutorial.
I can get it to parse and upload.
I can get the program to ask for and read the color input.
I can Serial.print the input color.
I CANNOT get inside my "if" statements.
[size=0.8em]Code: [url=https://arduinogetstarted.com/tools/arduino-code-highlighter]see how to post code[/url] [/size]--- |
|---|
|
``` [size=0.8em]int DT = 1000; //Delay 1 sec |
| int rPin = 8; //red led in pin 8 |
| int gPin = 9; //green in 9 |
| int bPin = 10; //blue in 10 |
| String msg1 = "What color LED would you like? (red, green, blue, or off) "; |
| String myColor; |
void [color=#5E6D03]setup/color {
// put your setup code here, to run once:
Serial.[color=#D35400]begin/color;
pinMode(rPin, OUTPUT); //set pinModes
pinMode(gPin, OUTPUT);
pinMode(bPin, OUTPUT);
}
void [color=#5E6D03]loop/color {
Serial.println (msg1); //ask for color
while (Serial.[color=#D35400]available/color == 0) { //wair
}
myColor = Serial.[color=#D35400]readString/color; //read input from serial monitor
Serial.[color=#D35400]println/color; //THIS WORKS!
//None of my 'if' statements work ***
if (myColor == "red") //THIS DOES NOT WORK
{
Serial.println("inside red loop");
digitalWrite(rPin, HIGH);
digitalWrite(bPin, LOW);
digitalWrite(gPin, LOW);
delay (DT);
}
if (myColor == "green") //THIS DOES NOT WORK
{
Serial.println("inside green loop");
digitalWrite(rPin, LOW);
digitalWrite(bPin, LOW);
digitalWrite(gPin, HIGH);
delay (DT);
}
if (myColor == "blue") //THIS DOES NOT WORK
{
Serial.println("inside blue loop");
digitalWrite(rPin, LOW);
digitalWrite(bPin, HIGH);
digitalWrite(gPin, LOW);
delay (DT);
}
delay (DT);
}[/size]
```
|