page12
Using Functions
A function is a self-contained piece of computer program that is collected in to a wrapper to make it easy for a programmer to use. Processing contains many already defined functions you can use in your programs. When you want to use a function you write a function call in to the program. Here is an example function call from the Blink Program.
pinMode( 13 , OUTPUT );
Name of the function: shows which function is being called. In Processing, the names are case sensitive (small and big letters must be correct). The name can't contain spaces.
Parameters of the function: Data values that are needed by the function are called “parameters”. They appear in brackets after the name. Different values are separated by commas. The number and types of data values is specified in the function definition.
In this case the first parameter is the pin number being set. The second parameter shows whether this pin is an INPUT or an OUTPUT.
If there are no parameters you still must include an empty pair of brackets.
Delimiter: In Processing each statement in the language must end with a semi-colon. This is called a delimiter. Missing semi-colons (or semi-colons in the wrong place) are a common source of problems.
Spaces allowed here
When the program reaches the function call it goes and performs the tasks defined by the function. Once the function as finished the program resumes just after the function call. It is possible for one function to call another function in a nested structure.
Built-In Functions
We have already seen three built-in functions: PinMode(), digitalWrite() and delay(). There are many others. You can explore them through the example sketches
http://arduino.cc/en/Tutorial/HomePage
or at
http://arduino.cc/en/Reference/HomePage