Getting rid of spurious data from Nintendo DS touchscreens

Hi, there

I am currently working on my honors project for university, it consists in a new type of MIDI controller that works via touchscreens. Basically what I have managed to do is receive the coordinates coming from the touchscreens in various float boxes in a Max/MSP patch using arduino and serial comunication, these coordinates will then be used to control all types of systems.

The problem is even though the touchscreens work correctly if you are not pressing them they send random data all the time to the number boxes, this means that I can’t use the touchscreens as triggers right now as they are always receiving data instead of outputting 0 when the screen isn't being pressed. I have tried changing the arduino code to no result, so I have thought about maybe making a system that validates information and only allows information to go through if it receives the same data twice and if it doesn’t it will output 0 as a result. I have been looking into it but have not found any way to achieve this yet. I would really appreciate if somebody could point me in the right direction.

Here is the arduino code I'm using at the moment

/*
 * Y1 to analog 0
 * X2 to analog 1
 * Y2 to analog 2
 * X1 to analog 3
 *
 */

int xVal = 0;
int yVal = 0;
int touchX;
int touchY;
int xPos;
int yPos;

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


void loop()
{
  // Set up the analog pins in preparation for reading the Y value
  pinMode( A1, INPUT ); // Analog pin 1
  pinMode( A3, INPUT ); // Analog pin 3
  pinMode( A0, OUTPUT ); // Analog pin 0
  digitalWrite( A0, LOW ); //  Analog pin 0 as  GND connection
  pinMode( A2, OUTPUT ); // Analog pin 2
  digitalWrite( A2, HIGH ); //  Analog pin 2 as  +5V connection
  yVal = analogRead( 1 ); // Read the Y value

  // Set up the analog pins in preparation for reading the X value
  // from the touchscreen
  pinMode( A0, INPUT ); // Analog pin 0
  pinMode( A2, INPUT ); // Analog pin 2
  pinMode( A1, OUTPUT ); // Analog pin 1
  digitalWrite( A1, LOW ); //  Analog pin 1 as  GND connection
  pinMode( A3, OUTPUT ); // Analog pin 3
  digitalWrite( A3, HIGH ); //  Analog pin 3 as  +5V connection
  xVal = analogRead( 0 ); // Read the X value


  //when touchscreen is not pressed it rests at certain coordinates
  //this makes sure the coordinates at rest don't get calculated
  touchX = xVal;
  if( touchX > 20 && touchX < 900 ) {

    ////   Here is where you need your minimum X value and Range of X
    ////  (touchX, minimum x, range of x, converts to 0-1024)
    xPos = map(touchX, 108.0, 899.0, 0, 1024); 


    xPos = constrain(xPos, 0, 1024);
  }
  touchY = yVal;
  if( touchY > 20 && touchY < 900 ) {

    ////   Here is where you need your minimum Y value and Range of Y
    ////  (touchY, minimum y, range of y, converts to 0-1024)
    yPos = map(touchY, 145.0, 892.0, 0, 1024);


    yPos = constrain(yPos, 0, 1024);
  }

  

 Serial.print(xPos);
 Serial.print(" ");
 Serial.print(yPos);
 Serial.println();

  delay(10);
}

Thanks in advance!!

Ian