Hardware Reference
In-Depth Information
pinMode()
The only line of code in the Blink sketch's setup function says pinMode(led,
OUTPUT); . pinMode() is one of many Arduino functions available to you. A
function is a collection of Arduino statements. You run the statements inside
a function when you call it by name. Functions each have a particular task
that they do. They sometimes take data inputs, which are called parame-
ters . They sometimes can give back data called return values . To understand
these concepts better, let's take a closer look at the use of pinMode() in the
Blink sketch.
By calling pinMode() , you're telling Galileo that you're going to use a particular
pin either as an input or an output. Therefore, it'll need two pieces of infor-
mation: the pin number and the mode (input or output). You need to do this
for each digital pin you plan to use before you use it. Typically, you'll do this
in the setup function.
Every function's parameters are passed to it by entering the values in paren-
theses after the name of the function. If there are multiple parameters, each
value is separated by a comma. In the case of pinMode() , the first parameter
is the number of the pin you want to set the mode of and the second value is
the pin's mode, written as INPUT or OUTPUT (in all caps).
To summarize, the syntax of pinMode() is:
pinMode(pin, mode);
The parameters of pinMode() are:
pin : the pin number
mode : either INPUT or OUTPUT
pinMode() doesn't return a value. In Chapter 4 , you'll take a look at functions
that return values.
In the Blink sketch, the statement pinMode(led, OUTPUT); takes the pin num-
ber value from the variable led (in this case, 13) and sets that pin as an output.
Arduino Language Reference
But how would you know this information if you didn't already have a topic
or teacher walking you through this? The Arduino Language Reference lists
each Arduino function, its purpose, parameters, and return values. Each even
has an example to demonstrate how to use it (see Figure 3-9 ).
Search WWH ::




Custom Search