Writing a function

You've already written two functions if you successfully compile an arduino sketch; they're called setup() and loop(). These functions return no values (in C they return a void type). In other languages they might be called procedures, but C doesn't differentiate - they're all functions.

Here's a toy example:

int plusone(int x)
{
    return x + 1;
}

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    static int n = 0; // static, so that its value is kept between function calls

    n = plusone(n);
    Serial.println(n, DEC);
    delay(5000);
}

In this example the fucntion plusone() takes a single integer as an argument and returns an integer.

Hope this gets you started. Look for a good book or online tutorial on learning C, and remember in arduino the function main() is already written for you, and it calls your setup() function once and calls your loop() function once every time through the event loop.

-j