I am using a Arduino Uno for an embedded systems course. My assignment is that I have to write a function that implements these specifications. Take an input from the user (‘R’, ‘G’, ‘B’) and display Red, Green or Blue. The function name must be dispColor(), the input must be char a and their is no return. My code is below, however whenever I type in an input I receive no output. Where is the error in my code?
String dispColor(char){
char a = Serial.read();
if (a == "R")
Serial.print("Red");
else if (a == "G")
Serial.print("Green");
else if (a == "B")
Serial.print("Blue");
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
String dispColor();
}
void loop() {
// put your main code here, to run repeatedly:
}
My Updated code
void dispColor(char a){
if(Serial.available()){
a = Serial.read();
if(a == 'R')
Serial.print("Red");
else if(a == 'G')
Serial.print("Green");
else if(a == 'B')
Serial.print("Blue");
}
}
void setup() {
Serial.begin(9600);
Serial.println("Please type in R, G, or B.");
dispColor();
}
void loop() {
}
"Red". Use single quotes for single characters, e.g.if (a == 'R')strcmpfunction