Callin a function from processing

Hello all!
Who could tell a newbie how to call an arduino function from processing?
I just need a simple example, for example I need a processing sketch that has 2 buttons.
When i press button 1, processing calls function1 in arduino and the MB led blinks say twice.
When I press button 2, a call is made to function2, which blinks the led say four times.

How do I do that?
I would like to see the processing + arduino codes, thanks

Who could tell a newbie how to call an arduino function from processing?

The same way that you call a function on my computer. That is you don't.

You CAN have Processing send a message to the Arduino, and have the Arduino read, parse, and understand that message.

Yep, thanks!
I know that, ok. But I need an example about how to do that, aarghh!

Processing:
myPort.write("Hey, there, Mr. Arduino, can you please blink the MB LED twice when you get around to it?");

Arduino:
You try something; we'll critique it.

Of course, you are free to send something from Process that might be a little easier to read, parse, and understand. Like, I don't know, maybe "1" for that function and "2" for the other one.

Ok, I did something and it worked of course. I loaded the standard Firmata to my mega and it was easy to do the job from processing. But lighting a led is not actually what I need. I need to understand how Arduino reads the data that is sent to it.
So, is there an serial interrupt to use or need I poll for sent data?
Lets suppose that Arduino gets an serial interrupt when data is sent to it. How/where does Arduino read the data (string or number(s)) so it can do something based on it? I don't think that Arduino needs to poll for serial data, there must be an interrupt, ok? So how do I get a pointer to the send data.

It's just that I have done so much using assembler and Delphi and Basic :-), and especially doing something with assembler requires that you understand to the detail almost everything you do.

Serial input is interrupt-driven and is buffered for you.
All you need to do is use "Serial.available()" to find out if there's anything in the buffere to read.

Thanks!
I figured that out myself, but I couldn't find available in the Arduino reference?? and I need to understand what I am doing, heh.
Maybe I just have to study more..this all is so new to me

Forgot to ask this:
Is it possible to write my own serial interrupt subroutine?
Suppose Arduino is doing whatever but is lazy not wanting to check again and again if there is data available.
So if there is an interrupt subroutine where lazy Arduino jumps always when data is available?, heh.
Or...am I sure I need this?..Arduino might of course execute serial.available() every now and then, but...hmm...

You could use serialEvent

Is it possible to write my own serial interrupt subroutine?

Several thoughts come to mind. Summarizing them, the answer is no.

There is already an interrupt service routine that is triggered when serial data arrives. That routine gets the byte, and stores in an a buffer.

It would be possible to replace that routine, to do more work, BUT, the routine is NOT going to trigger behavior in your sketch.

Suppose Arduino is doing whatever but is lazy not wanting to check again and again if there is data available.

The Arduino is not lazy. It is working all the time. Flat out 100% CPU utilization all the time. YOU are the one being lazy, not wanting to write code to check to see if there is data available. Believe me, it is far simpler to call Serial.available() in your code than it is to try to merge the serial interrupt behavior into your code. The serial interrupt, by the way, if fired when EACH byte arrives. The arrival of ONE byte does NOT mean that your sketch has enough data to cause it to do something.

Besides, the idea behind an interrupt is that it TEMPORARILY suspends what the Arduino is doing, does something else, and then resumes what it was doing. If you wand to cause different behavior when the code resumes, you have to set a flag in the ISR, and have the Arduino periodically check that flag. That is no different from checking whether there is serial data to read.

So if there is an interrupt subroutine where lazy Arduino jumps always when data is available?, heh.

The fundamental assumption in this statement is false. Therefore, the question is meaningless.

Or...am I sure I need this?

If you are, you are wrong.

PaulS:
Thanks! After considering how I have coded these things using assembler (from the scratch it is), I agree on what you said, and everything can be done using SerialEvent etc.

and everything can be done using SerialEvent

The serialEvent() function is called at the end of loop(), if there is any serial data to be dealt with. All that means is that some other code calls Serial.available(), instead of you calling it in loop(). There is no time savings, and data isn't dealt with any sooner.