average or median for noisy data

Hallo board
I have a simple coding question, but first here's my hardware set up -

I have hacked a 4-wire resistive touch panel, as follows:
panel pins 1-4 = X+, Y+, X-, Y-;
X+ =(5V or read) X- =(gnd or open);
Y+ =(5v or read) Y- =(gnd or open);
the read lines are pulled down to ground

The circuit has been optimized for clean voltages, and the data is also fairly clean when using a stylus or pen etc. When using a fingertip, however, the voltages ramp up to the XY location, representing fingertip flesh expansion and contraction during contact and release; such jitter is not present when using a stylus etc.

Here's my code:

/* TOUCHSCREEN ELECTRODE PAIRS= X1-X2, Y1-Y2
connect as A0=X1, A1=Y1, A2=X2, A3=Y2; 
A0 and A1 alternate readings, so 1kR pulldown to gnd on these;
'open circuit' floating values cured via digitalWrite to 0v on
A2 and A3
*/
int xVal = 0;
int yVal = 0;

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

void loop()
{
pinMode(A0, OUTPUT); 	//analog 0 = gnd; 			
pinMode(A2, OUTPUT);	//analog 2 = +5v;
pinMode(A1, INPUT);	//analog 1 = signalRead; 		
pinMode(A3, INPUT);	//switch3			

digitalWrite(A0, LOW);	//gnd
digitalWrite(A2, HIGH);	//+5v

delay(5);		//let voltage settle
xVal = analogRead(A1);	//read pin 1
xVal/=4;                //0-1024 = 0-128
digitalWrite(A2, LOW);  //back to gnd

//switch pinModes to read other axis
pinMode(A3, OUTPUT);	//analog 3 = +5v
pinMode(A1, OUTPUT);	//analog 1 = gnd
pinMode(A2, INPUT);	//switch2
pinMode(A0, INPUT);	//analog 0 = signalRead

digitalWrite(A1, LOW);	//gnd
digitalWrite(A3, HIGH);	//+5v
delay(5);
yVal = analogRead(A0);
yVal/=4;
digitalWrite(A3, LOW);  //back to gnd

//Serial.print("X= ");
Serial.print(xVal,BYTE);
//Serial.print("\t\tY= ");
Serial.print(yVal,BYTE);
Serial.print(255, BYTE);
delay (40);
}

Can someone suggest a simple array or forLoop to average several readings, inside each "axis-cycle", before sending them out?

Thanks
n00bmeister

Where you read xVal, do it in a loop:

xVal = 0;
for(byte i=0; i<10; i++)
{
   xVal += analogRead(A1);
}
xVal /= 10;

thanks Paul, most helpful

n00meister

See also playground articles

PaulS:
Where you read xVal, do it in a loop:

xVal = 0;

for(byte i=0; i<10; i++)
{
   xVal += analogRead(A1);
}
xVal /= 10;

Hi Paul, how can I set it in a way that it always skip the first 2 readings?

for(byte i=0; i<2; i++)
{
   analogRead(A1);
}
xVal = 0;
for(byte i=0; i<10; i++)
{
   xVal += analogRead(A1);
}
xVal /= 10;