lease discuss this Arduino code int redPin = 10; //set red LED pin to 10 int bluePin = 11; //set blue LED pin to 11 String colorChoice; //Will hold users input of color choice void setup() { // put your setup code here, to run once: pinMode(bluePin, OUTPUT); //Set redPin to be an output pinMode(redPin, OUTPUT); //Set greenPin to be an output Serial.begin(9600); //Turn on Serial port } void loop() { Serial.println("What color do you want to blink up, red or blue?"); //Prompt user for color while (Serial.available() == 0) { } //Wait for input colorChoice = Serial.readString(); if (colorChoice == "red") { digitalWrite(redPin, HIGH); delay(1000); digitalWrite(redPin, LOW); delay(1000); } if (colorChoice == "blue") { digitalWrite(bluePin, HIGH); delay(1000); digitalWrite(bluePin, LOW); delay(1000); } if (colorChoice!="red" && colorChoice != "blue") { Serial.println("That is not a valid color choice, please try again"); Serial.println(""); } }
Please discuss this Arduino code
int redPin = 10; //set red LED pin to 10 int bluePin = 11; //set blue LED pin to 11
String colorChoice; //Will hold users input of color choice
void setup() {
// put your setup code here, to run once: pinMode(bluePin, OUTPUT); //Set redPin to be an output pinMode(redPin, OUTPUT); //Set greenPin to be an output Serial.begin(9600); //Turn on Serial port
}
void loop() {
Serial.println("What color do you want to blink up, red or blue?");
//Prompt user for color
while (Serial.available() == 0) { } //Wait for input colorChoice = Serial.readString();
if (colorChoice == "red") { digitalWrite(redPin, HIGH); delay(1000); digitalWrite(redPin, LOW); delay(1000);
}
if (colorChoice == "blue") { digitalWrite(bluePin, HIGH); delay(1000); digitalWrite(bluePin, LOW); delay(1000);
}
if (colorChoice!="red" && colorChoice != "blue") {
Serial.println("That is not a valid color choice, please try again");
Serial.println("");
}
}
Step by step
Solved in 2 steps