If statement doesn't work

edited May 2017 in Arduino

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);
}
Tagged:

Answers

Sign In or Register to comment.