EasyManua.ls Logo

Sparkfun Electronics RedBoard - Page 65

Sparkfun Electronics RedBoard
88 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Component: Image Reference:
Jumper Wire
Pin 9
j9
i7
Jumper Wire
GND
Jumper Wire
Piezo Buzzer
+
-
f9 f7
Arduino contains a wealth of built-in functions that are useful for all kinds of things.
(See http://arduino.cc/en/reference for a list). But you can also easily create your
own functions. First, we need to declare a function. Here's a simple example named
"add," which adds two numbers together and returns the result. Let's break it down.
Your functions can take in values ("parameters"), and return a value, as this one does.
If you'll be passing parameters to your function, put them (and their types) in the
parentheses after the function name. If your function is not using any parameters, just
use an empty parenthesis () after the name.
If your function is returning a value from your function, put the type of the return
value in front of the function name. en in your function, when you're ready to
return the value, put in a return(value) statement. If you won't be returning a value,
put "void" in front of the function name (similar to the declaration for the setup()
and loop() functions).
When you write your own functions, you make your code neater and easier to re-use.
See http://arduino.cc/en/reference/functiondeclaration for more information
about functions.
Creating your own functions:
int add(int parameter1, int parameter2)
{
int x;
x = parameter1 + parameter2;
return(x);
}
Page 63