Touch screen to Processing

Hi, im trying to create a program so that I can draw an a Nintendo DS touch screen, and a program on processing will draw where it is on the touch screen.

Arduino Code:

int y1 = A0;
int x2 = A1;
int y2 = A2;
int x1 = A3;

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

int readX(){
  pinMode(y1, INPUT);
  pinMode(x2, OUTPUT);
  pinMode(y2, INPUT);
  pinMode(x1, OUTPUT);

  digitalWrite(x2, LOW);
  digitalWrite(x1, HIGH);

  delay(5); //pause to allow lines to power up

  return analogRead(y1);
}

int readY(){

  pinMode(y1, OUTPUT);
  pinMode(x2, INPUT);
  pinMode(y2, OUTPUT);
  pinMode(x1, INPUT);

  digitalWrite(y1, LOW);
  digitalWrite(y2, HIGH);

  delay(5); //pause to allow lines to power up

  return analogRead(x2);
}

void loop()
{
  int x = readX();
  int y = readY();

  Serial.print(x);
  Serial.print(',');
  Serial.print(y);
  Serial.println(' ');

  
  

  delay(0); //just to slow this down so it is earier to read in the terminal - Remove if wanted

}

Processing Code:

import processing.serial.*;
Serial myPort;


void setup()
{
  size( 800, 600 );
  background( 0 );
  myPort = new Serial(this, Serial.list()[2], 9600);
  myPort.bufferUntil(' ');
}



void draw() {  
}

void serialEvent( Serial myPort )
{
  String inString = myPort.readStringUntil( '\n' );

  if( inString != null )
  {
    inString = trim( inString );
    int[] coords = int( split( inString, ',' ) );
    background(0);
    stroke(255);
    fill(255);
    int x = coords[0];
    int y = coords[1];
  ellipse(x, y, 10, 10);
  }
}

It somtimes says "NullPointerException" and WARNING: RXTX Version mismatch
How can I fix this?

The RXTX library mismatch can generally be ignored.

The NullPointerException is most likely happening because you are referencing the 3rd element in a list without three elements.

  myPort = new Serial(this, Serial.list()[2], 9600);

Do you KNOW that there are three serial ports available, and that the Arduino is connected to the thord one?

Add

println(Serial.list());

just before the myPost declaration, to verify that there are at least three COM ports listed.

the Arduino is connected to the thord one?

Yes, the Arduino is connected to the third one.

Somtimes I also get the error "disabling serialEvent() for //./COM3"