We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi guys,
So with processing i'm reading a text file into a string. I only want to send data to the serial port if there is new data in the text file. So in the setup part i created a string[] lines that loads into a string the content of the text file.
In the main loop i create a string[] linesTemp that loads the content of the same file. Then i make a if to compare the two strings. If the two strings are equal i print "same". The issue is that the two strings have the same values but i don't know why it doesn't go into the if statement and print "same" in the console. Thanks !
Here is my code :
import processing.serial.*;
import java.io.*;
Serial myPort;
String[] lines;
int b =0;
int c =0;
void setup() {
//Make sure the COM port is correct
myPort = new Serial(this, "COM5", 9600);
myPort.bufferUntil('\n');
lines = loadStrings("matrice.txt");
}
int counter=0;
void draw() {
String[] linesTemp = loadStrings("matrice.txt");
for (int a=0; a<(lines.length); a++)
{
println("ligne : ", b++, lines[a]);
println("ligneTemp : ", c++, linesTemp[a]);
if (linesTemp[a] == lines[a])
{
println("same");
} else if (linesTemp[a] != lines[a]) {
lines[a] = linesTemp[a];
myPort.write(""+linesTemp[a]);
}
}
delay(1000);
}
Answers
https://Processing.org/reference/String_equals_.html
https://processing.org/reference/String.html
God thank you sir ! I'm sorry i'm using processing for the first time so i'm no very used to it, but thank you very much !!!