dimanche 13 novembre 2016

.equals never evaluates to true in processing

I have programmed an Engduino to measure temperature in the room using it's thermistor and output the values to the Serial port; when the program begins, it outputs "start temp" and when the program ends it outputs "end temp", and in between it outputs the temperature value every 2 seconds. I'm using .readString in Processing to read these values as they're being measured.

String str = myEngduino.readString();
 if(str!=null){
    println(str);
}

This code works fine and the values being printed to the console are indeed "start temp", then the temperatures as they're read, then "end temp" when the program finishes. So I don't understand why the if statement in this code never evaluates to true:

String str = myEngduino.readString();
if(str!=null){
    println(str);
    if(str.equals("start temp")){
      println("START");
    }
}

str is definitely set to "start temp" because it is printed out to the console, so why won't my if statement evaluate to true at this point?

Aucun commentaire:

Enregistrer un commentaire