Troble reading Arduino in SuperCollider

Hey I am having trouble getting a consistent reading in SuperCollider from my Arduino.

Basically I have a pressure mat attatched, and it should read the numbers 1023 when no one is on it, and 0 when some one is on it.
I have connected everything perfectly, but SuperCollider seems to read the values from the Arduino smoothly for a few seconds and then pauses for a few minutes and then spits all the values it missed out at once.

I would really appreciate anyone's help as this has been bugging me for months.

SuperCollider Coding:

s.boot; //boot server

( //one time evaluation!! please....
p = Routine(
{
"recordings/Diss/Coding/01SynthDef.rtf".loadPaths;
1.wait;
"recordings/Diss/Coding/02ReadBuf.rtf".loadPaths;
1.wait;
"recordings/Diss/Coding/03Buffers.rtf".loadPaths;
4.wait;
"recordings/Diss/Coding/04StructureOfEnvironments.rtf".loadPaths;
4.wait;
"recordings/Diss/Coding/05Environments.rtf".loadPaths;
1.wait;
"recordings/Diss/Coding/06Transition.rtf".loadPaths;
1.wait;
"recordings/Diss/Coding/05Environments.rtf".loadPaths;
});
p.reset.play;
)

//wait for 20 seconds

( //evaluate composition
c =[~environment01, ~environment02, ~environment03,
~environment04, ~environment05, ~environment06,
~environment07, ~environment08, ~environment09,
~environment10, ~environment11].choose;
)

p = ArduinoSMS("/dev/tty.usbserial-A4001nK8", 115200);
p.action = { |... msg| ~a = msg[1].postln; };

(

fork {
10000.do {
p.send($r, $a);
1.wait;
}
};

~rout1 = Routine ({inf.do {if (~a<10, {"start the sound".postln; c.play;~rout2.reset.play; nil.alwaysYield;}); 0.5.wait;}});

~rout2 = Routine ({inf.do {if (~a>10, {"stop the sound".postln; SystemClock.clear;s.freeAll; ~rout1.reset.play; nil.alwaysYield;} ); 0.5.wait;}});

~rout1.reset.play;
)
p.close; //to close Arduino coding

Arduino Coding:

/*

  • Arduino2Max
  • Send pin values from Arduino to MAX/MSP
  • Arduino2Max.pde

  • Latest update: September 2007

  • Copyleft: use as you like
  • by djmatic
  • Based on a sketch and patch by Thomas Ouellet Fredericks tof.danslchamp.org
  • Don't worry about the LED (which you can connect to digital 13 if you want) as it doesn't contribute anything new.
  • Attach a potentiometer to 5v and Ground (two outer connections), and the sensor (central connection) to Analogue in 5.
  • In fact, the code below reads ALL the analogue pins, so you can use any...
    */

int x = 0; // a place to hold pin values
int led1Pin = 12; // LED #1 is connected to pin 12
int led2Pin[] = { 3, 4 }; // LED is connected to pin 12
int timer = 55; // The higher the number, the slower the timing.
int num_pins = 2;
int switchPin1 = 1;
int switchPin2 = 2; // switch is connected to pin 2
int val1; // variable for reading the pin status
int val2;

void setup() {
Serial.begin(115200);
int i;
for (i = 0; i < num_pins; i++) // the array elements are numbered from 0 to num_pins - 1
pinMode(led2Pin*, OUTPUT); // set each pin as an output*

  • pinMode(led1Pin, OUTPUT); // Set the LED #1 pin as output*
  • pinMode(switchPin1, INPUT); // Set the switch pin as input*
  • pinMode(switchPin2, INPUT);*
  • }*
    void loop()

{

  • val1 = analogRead(switchPin1);*

  • if (val1 == HIGH) { // check if the button is pressed*

  • digitalWrite(led1Pin, HIGH); *

  • delay(4000);*

  • digitalWrite(led1Pin, LOW); // turn LED #1 of*

  • delay(90000); *

  • }*

  • val2 = digitalRead(switchPin2);*

  • if (val2 == LOW) { // check if the button is pressed*

  • digitalWrite(led1Pin, HIGH); *

  • delay(800);*

  • digitalWrite(led1Pin, LOW); // turn LED #1 of*

  • }*

  • int i;*

  • for (i = 0; i < num_pins; i++) { // loop through each pin...*
    _ digitalWrite(led2Pin*, HIGH); // turning it on,_
    _
    delay(timer); // pausing,_
    _ digitalWrite(led2Pin, LOW); // and turning it off.
    }_
    for (i = num_pins - 1; i >= 0; i--) {
    _ digitalWrite(led2Pin, HIGH);
    delay(timer);
    digitalWrite(led2Pin, LOW);
    }*

    if (Serial.available() > 0){ // Check serial buffer for characters_

* if (Serial.read() == 'r') { // If an 'r' is received then read the pins*

for (int pin= 0; pin<=5; pin++){ // Read and send analog pins 0-5
* x = analogRead(pin);*
* sendValue (x);*
* }*
for (int pin= 2; pin<=13; pin++){ // Read and send digital pins 2-13
* x = digitalRead(pin);*
* sendValue (x);*
* }*

* Serial.println(); // Send a carriage returnt to mark end of pin data.*
* delay (5); // add a delay to prevent crashing/overloading of the serial port*

* }*

}
}
void sendValue (int x){ // function to send the pin value followed by a "space".
Serial.print(x);
Serial.print(32, BYTE);
}

can no one help??
does no one use Arduino with SuperCollider???