Arduino and Processing communication

Hello,

Pardon my English I am French student I have a problem of communication between an arduino UNO rev3 and processecing I would like know how to do communicate the two I managed to retrieve a value, I can display it independent but I cannot use it as a variable for a test

   text(Power,10,10);  //OK

Power is a String value

  void Etat_Arduino(int X,int Y)
  {
   if (Power == "Y")  //Yes or No     the test is always wrong even when the test should be true
   {
   text("OK",X,Y);
   }
   else
   {
   text("ERROR",X,Y);
   }
  }

However, if I declare String Power = "Y"; The program displays "OK" but I am obliged to declare String Power = "N"; or "";

Could you help me, where can I find tutorials to explain the communication between Arduino and Processing? My program must receive the Arduino variables but also be capable of change them

Thank you

Have you read this: http://www.arduino.cc/playground/Interfacing/Processing On this page are examples at section "4. communication": http://arduino.cc/hu/Tutorial/HomePage

Yes, I read. it slightly helped me. I can not always run my test

String Power = "";

if (Power == "1") //OK => Connect
{
text();
}
else // No Connect
{
text();
}

void serialEvent (Serial port)
  {
    data = port.readStringUntil('.');
    data = data.substring(0, data.length() - 1);
    
    index_Power = data.indexOf(",");     //  My arduino send "1"
    Power = data.substring(0, index_Power );
  
  }

That snippet makes it appear that serialEvent() is defined inside the draw() function. That is most certainly NOT allowed.

It is why we don’t want you posting snippets. Post ALL of your code.

  import processing.serial.*;
  Serial port;
  
  String data = "";
  String Power = "No Connect !";
  int index_Power = 0;
  int index_Alarme =0;
  
  void setup()
  {
   background(0,0,0);
   size(600,400);
   port = new Serial(this, "COM11", 57600);
   port.bufferUntil('.'); 
  }   
  
  void draw()
  {
  Etat_Arduino(Power,112,103); //print : "ERROR !" instead of "OK !"
  fill(46, 209, 2);
  text(Power, 70, 320);   //print : "1"
  }
  
  void serialEvent (Serial port)
  {
  data = port.readStringUntil('.');
  data = data.substring(0, data.length() - 1);
  index_Power = data.indexOf(",");
  Power = data.substring(0, index_Power );
  }
  
  void Etat_Arduino(String V,int X,int Y)
  {
  if (V == "1")
  {
  text("OK !",X,Y);   
  }
  else
  {
  text("ERROR !",X,Y);
  }
  }

I would also like to change the variable that the program of the arduino send me, for example, it sent me "Power = 1" and I want to "Power = 0" so I sent it 0, and I will add another variables, how can I do for the arduino to receive. and processing sent it?

What is sending data to the Processing application?

  data = port.readStringUntil('.');

So, what is in data now?

  data = data.substring(0, data.length() - 1);

Make a substring of all the characters in data, and store in data. How useful is that?

 index_Power = data.indexOf(",");

Suppose data doesn't contain a ,. What will be the value in index_Power?

  Power = data.substring(0, index_Power );

Does is make sense to always call this function? What is the output if index_Power is -1?

  Etat_Arduino(Power,112,103); //print : "ERROR !" instead of "OK !"

What does this comment mean? If you want the function to always print "ERROR!", remove the code that does otherwise.

I would also like to change the variable that the program of the arduino send me, for example, it sent me "Power = 1" and I want to "Power = 0" so I sent it 0, and I will add another variables, how can I do for the arduino to receive. and processing sent it?

Is the Arduino the master, and the Processing application the slave? If so, it doesn't make sense for you to be modifying what the Arduino sent, and telling it it was wrong.

The Processing sketch that you posted is not expecting an input string that contains "Power = 1" or "Power = 1" or any variation that contains the string "Power =". There is nothing in the Processing application that changes the value in Power, except for that code that sets it based on what it receives from the serial port.

You haven't posted the Arduino code at all.

So, it isn't clear how to help you.