I am using Processing to display data coming into the serial port. I have simple string values coming into the serial port.
I have cut down all my code to this basic point of failure and I cannot understand why it fails. The if statement never evaluates to true. (I'm not trying to compare strings with = or == )
Please help if you know why this is happening :) I'd really appreciate an answer.
Ugh Alright then, since I don't have a reputation of 10, I won't post the helpful screenshot. Here is the code that fails:
enter code here
import processing.serial.*;
Serial myPort;
String val; //Data recieved from the serial port
void setup() {
size(400,300);
String portName = Serial.list()[2]; //change the 0 to a 1 or 2 etc. to match your port //1 or 2 for USB on the Mac
myPort = new Serial(this, portName, 9600);
myPort.bufferUntil('\n');
}
void serialEvent (Serial myPort){
val = myPort.readStringUntil('\n');
print(val);
if(val != null){
if(val.equals("New sample set")){
print("yes\n");
} else {
print("not equal\n");
}
}
}
void draw() {
//The serialEvent controls the display
}
I have tried taking out the spaces and making it only one letter, but this did not help. I have tried using if(val.equals("New sample set")==true) but that didn't help either.