If statements not evaluating correctly
in
Programming Questions
•
11 months ago
Hello. I'm hoping that someone could explain why the following "if" statements do not evaluate?
String arduino_color="";
String cheer_color[] = loadStrings(" http://api.thingspeak.com/channels/1417/field/1/last.txt");
void draw()
{
String cheer_color[] = loadStrings(" http://api.thingspeak.com/channels/1417/field/1/last.txt");
{
String cheer_color[] = loadStrings(" http://api.thingspeak.com/channels/1417/field/1/last.txt");
//set possible color states as one Character Strings - eg. red=R
if (cheer_color[0].equals("red")) {
String arduino_color="R";
}
if (cheer_color[0].equals("green")) {
String arduino_color="G";
}
if (cheer_color[0].equals("blue")) {
String arduino_color="B";
}
if (cheer_color[0].equals("cyan")) {
String arduino_color="C";
}
if (cheer_color[0].equals("white")) {
String arduino_color="W";
}
if (cheer_color[0].equals("warmwhite")) {
String arduino_color="H";
}
if (cheer_color[0].equals("purple")) {
String arduino_color="P";
}
if (cheer_color[0].equals("magenta")) {
String arduino_color="M";
}
if (cheer_color[0].equals("yellow")) {
String arduino_color="Y";
}
if (cheer_color[0].equals("orange")) {
String arduino_color="O";
}
if (cheer_color[0].equals("red")) {
String arduino_color="R";
}
if (cheer_color[0].equals("green")) {
String arduino_color="G";
}
if (cheer_color[0].equals("blue")) {
String arduino_color="B";
}
if (cheer_color[0].equals("cyan")) {
String arduino_color="C";
}
if (cheer_color[0].equals("white")) {
String arduino_color="W";
}
if (cheer_color[0].equals("warmwhite")) {
String arduino_color="H";
}
if (cheer_color[0].equals("purple")) {
String arduino_color="P";
}
if (cheer_color[0].equals("magenta")) {
String arduino_color="M";
}
if (cheer_color[0].equals("yellow")) {
String arduino_color="Y";
}
if (cheer_color[0].equals("orange")) {
String arduino_color="O";
}
println(cheer_color[0]);
println(arduino_color);
}
println(arduino_color);
}
cheer_color is retrieved and returns the correct value (e.g. "blue") but arduino_color never gets set to a value (e.g. "B").
Eventually what I'm hoping to accomplish will be to pass the value of cheer_color[0] to an arduino via the serial port, and I figured a 1 Byte string would be the way to go. I just can't see what's wrong with the if statement...
Thanks!
1