How can I play iTunes with Arduino & photoresistor?

Hello,

I am trying to create a project that will take the value of the photoresistor and use that value to command iTunes to play or pause, depending on the light level read by the photoresistor. I tried using Apple Script Proxy from TinkerIt!, but there was a delay between the Arduino’s serial communication and the Apple Script Proxy app. I can’t seem to figure out why it takes so long for the Script Proxy to read the print out from the Arduino. The serial monitor from the Arduino program displays the information immediately, so I don’t know what the problem is. If there is a better way to do this (possibly through the Processing 2 program?), please let me know. Thank you.

//Code to read voltage from photoresistor, and use that data to play or pause iTunes using serial port.

void setup(){
Serial.begin(115200);
pinMode(13,OUTPUT); //Built in LED on pin 13 lights up whenever photoresistors voltage is high.

}
void loop()
{
int lightlevel=analogRead(0); //reads the light level from the photoresistor and assigns it to the variable called lightlevel
delay(500); //wait one second.
if (analogRead(0)>lightlevel+70) //if the light level is greater then photoresitors’s voltage, it plays music.
{
digitalWrite(13,HIGH); //turn LED on
Serial.print(“B”);//send signal to Apple Sctipt Proxy program through serial port, which interprets “B” as an applescript command.
}
delay(500);
if (analogRead(0)<lightlevel-30) //if the light level is less then photoresitors voltatage, it pauses the music.
{
digitalWrite(13,HIGH); //turn LED on
Serial.print(“A”);//send signal to Apple Sctipt Proxy program through serial port, which interprets “A” as an applescript command.

}
else{
digitalWrite(13,LOW); //turns LED off.

}
}

int lightlevel=analogRead(0); //reads the light level from the photoresistor and assigns it to the variable called lightlevel

Are these excessively long, perfectly obvious, comments really necessary?

The serial monitor from the Arduino program displays the information immediately, so I don’t know what the problem is.

Well, clearly, you know where the problem ISN’T? So, why post the code that IS working, and not post the code that ISN’T working?

Thank you for your advice.