Arduino ==> Processing Communication

HELP!!!
Here is the code, I want make a “drums” using Arduino & Processing. Right now, I’m done the coding part in arduino, but I want using Processing to listen Arduino data, then processing can “call” a sound sample.

There is the arduino code(Using Arduino MEGA2560):

int fsrPin1 = 0; // the FSR and 10K pulldown are connected to a0
int fsrPin2 = 1;
int fsrPin3 = 2;
int fsrReading1; // the analog reading from the FSR resistor divider
int fsrReading2; 
int fsrReading3; 
int LEDpin1 = 13; 
int LEDpin2 = 12; 
int LEDpin3 = 11; 
int LEDbrightness1;
int LEDbrightness2;
int LEDbrightness3;

void setup(void) {
// We'll send debugging information via the Serial monitor
Serial.begin(9600); 
pinMode(LEDpin1, OUTPUT);
pinMode(LEDpin2, OUTPUT);
pinMode(LEDpin3, OUTPUT);
}

void loop(void) {
fsrReading1 = analogRead(0); 

LEDbrightness1 = map(fsrReading1, 0, 1023, 0, 255);
analogWrite(LEDpin1, LEDbrightness1);

Serial.print("Analog reading1 = ");
Serial.print(fsrReading1); // the raw analog reading


// We'll have a few threshholds, qualitatively determined
if (fsrReading1 < 10) {
Serial.println(" - No pressure");
} else if(fsrReading1 < 200) {
Serial.println(" - Light touch");
} else if (fsrReading1 < 500) {
Serial.println(" - Light squeeze");
} else if (fsrReading1 < 800) {
Serial.println(" - Medium squeeze");
} else {
Serial.println(" - Big squeeze");
}
delay(50);

fsrReading2 = analogRead(1); 

LEDbrightness2 = map(fsrReading2, 0, 1023, 0, 255);
analogWrite(LEDpin2, LEDbrightness2);

Serial.print("Analog reading2 = ");
Serial.print(fsrReading2); // the raw analog reading

// We'll have a few threshholds, qualitatively determined
if (fsrReading2 < 10) {
Serial.println(" - No pressure");
} else if(fsrReading2 < 200) {
Serial.println(" - Light touch");
} else if (fsrReading2 < 500) {
Serial.println(" - Light squeeze");
} else if (fsrReading2 < 800) {
Serial.println(" - Medium squeeze");
} else {
Serial.println(" - Big squeeze");
}
delay(50);

fsrReading3 = analogRead(2); 

LEDbrightness3 = map(fsrReading3, 0, 1023, 0, 255);
analogWrite(LEDpin3, LEDbrightness3);

Serial.print("Analog reading3 = ");
Serial.print(fsrReading3); // the raw analog reading

// We'll have a few threshholds, qualitatively determined
if (fsrReading3 < 10) {
Serial.println(" - No pressure");
} else if (fsrReading3 < 200) {
Serial.println(" - Light touch");
} else if (fsrReading3 < 500) {
Serial.println(" - Light squeeze");
} else if (fsrReading3 < 800) {
Serial.println(" - Medium squeeze");
} else {
Serial.println(" - Big squeeze");
}
delay(50);
}

Could u give me some idea about processing code?

Thanks!!!

Well take any processing example dealing with serial communication.

You will need to either parse all the very verbose output you have in your arduino at the moment or (better) since this is a computer talking to a computer heavily simplify the way they talk to each other and only pass the data and some start/end frame info.

Your arduino will also have to listen to serial input to see if processing is sending stuff.

I'd suggest to start from any working serial example with two way communication - there are tons on the web - understand that code and how serial works (do read and understand Robin's excellent post on serial basics ) - and then work your way of merging your code into this

LEDbrightness1 = map(fsrReading1, 0, 1023, 0, 255);

The map() function is a very expensive way to divide by 4.

Could u give me some idea about processing code?

You should definitely have some.

If you are writing your code in Java you might take a look at https://github.com/rxtx/rxtx

rxtx is a library and the correct DLL's to interface with the Arduino serial and the Java program.

I have been using it for acquisition and control and it works pretty well. There is a lot of example code.

I have not used the rxtx libraries for MAC, but on a PC it works fine.