Use the Arduino Processing Interface

Hi .

Thanks for your answer.

I am not sure to have well understood what you told me ( English is not my maternal language).

So I have found an other solution to receive two data from Arduino to Processing

And I have found those programs for Processing and Arduino

First Processing Program

// import the Processing serial library
import processing.serial.*;    
Serial myPort; // The serial port
 
// Test values
int v1 =0;
int v2 = 255;
int x;
 
void setup() {
  size(640,480);
  // Open serial port
  //printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
 
  // Read bytes into a buffer until you get a linefeed (ASCII 10):
  myPort.bufferUntil('\n');
 
  //draw with smooth edges:
  //smooth();
  background(255);
}
 
void draw() {
 
  // Draw circles
  fill(#ff0000);
  ellipse(x, v1, 5, 5);
  fill(#00ff00);
  ellipse(x, v2, 5, 5);
 
  // Update x position
  x++;
 
  // Refresh screen
  if (x > 600) {
    background(255);
    x = 0;
  }
}
 
// serialEvent  method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():
void serialEvent(Serial myPort) {
 
  // read the serial buffer:
  String myString = myPort.readStringUntil('\n');
 
  // if you got any bytes other than the linefeed:
  myString = trim(myString);
 
  // split the string at the commas
  // and convert the sections into integers:
  int values[] = int(split(myString, ','));
 
  if (values.length > 0) {
    v1 = values[0];
    v2 = values[1];
    //println(v2);
  }
}

and this one for Arduino but it doesn’t seem to work.

// Send serial data to Processing
// Data are separated by a ",", so you could send any number of data
 
int firstSensor = 0;    // first analog sensor
int secondSensor = 255;   // second analog sensor
 
void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
}
 
void loop() {
 
    // Update Data with linear values
    firstSensor += 10; 
    secondSensor -= 20;
    if (secondSensor < 0)  secondSensor = 255;
    if (firstSensor > 255)  firstSensor = 0;
 
    // Send Data
    Serial.print(firstSensor);
    Serial.print(","); // séparateur
    // Avec println on ferme le paquet de valeur, car "ln"
    Serial.println(secondSensor); 
 
    // Sampling rate
    delay(5);
}

I have got two lines who go straight on