Multiple lines in the same graph using Processing

Is it possible to plot multiple lines in the same graph using Processing? I want to read the input from two potentiometers and plot them simultaneously, like in the Graph example. Thanks in advance.

Is it possible to plot multiple lines in the same graph using Processing?

Of course.

I want to read the input from two potentiometers and plot them simultaneously, like in the Graph example.

Fine by me. Go ahead. If you have questions, be sure to ask them.

Ok. I know how to read the inputs from the potentiometers but I don't know how to modify the Processing code to show two lines. Could you please help me?

Andre,
The more information you provide the better answer you get. So if you post your code you have, it is much easier to help you.

Does processing get the 2 potentiometer values? Does that part work?

Sorry for the lack of information. In Arduino I’m using the following code:

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(analogRead(A0));
  Serial.println(analogRead(A1));
  delay(2);
}

The Processing code is:

import processing.serial.*;
 
Serial myPort;
int xPos = 1;
 
void setup() {

size(400, 300);        

myPort = new Serial(this, Serial.list()[8], 9600);
myPort.bufferUntil('\n');
background(0);
}

void draw() {
}
 
void serialEvent(Serial myPort) {

String inString = myPort.readStringUntil('\n');
 
if (inString != null) {
  inString = trim(inString);
  float inByte = float(inString); 
  inByte = map(inByte, 0, 1023, 0, height);
 
  stroke(127,34,255);
  line(xPos, height, xPos, height - inByte);
 
  if (xPos >= width) {
    xPos = 0;
    background(0); 
  } 
  else {
  xPos++;
}
}
}

The Processing part doesn’t work as I expect, it shows two lines but there is a lot of noise in the figure.

it shows two lines but there is a lot of noise in the figure

The noise can only be comming from the hardware not the plotting software . Have you printed the results to see what you are getting?

You need to send something like “190, 450”. Without some means of knowing which value is first, you can (too) easily get out of sync.

Since you are sending an int, using float in Processing doesn’t make sense.

Processing can split the string received into an array of ints. Then, you use each one to draw a line. Use different colors to distinguish them.

Thanks for the answers.
I solved the noise issue increasing the delay time.
Could you give me a example using split and change line color in Processing?
Sorry, I'm newbie in Processing programing.

String test = "123,456,789";

void setup()
{
  int[] things = int(split(test, ','));
  for(byte b=0; b<things.length; b++)
  {
    print("things[");
    print(b);
    print("] = ");
    println(things[b]);
  }
}

void draw()
{
}

The stroke() function defines the color to be used to draw the next line.