Hardware Reference
In-Depth Information
tion and begin executing the statements there. This
loop()
function will be run not
once, but over and over again until the power is turned off.
Now that you have context, you can actually start writing some code in the
setup()
and
loop()
functions. Start by putting something in the
setup()
function. Change the
setup()
function to look like the code in the following screenshot:
There are two changes that should have been made. The first change is adding the
int
led = 13;
statement. This statement sets up a storage location in the memory named
led
and puts the value
13
into this variable. Since this variable is declared outside of any
function, it is a global variable. Global variables are available to all functions. This partic-
ular variable will hold the value of the output pin that will light up your LED. Note that
you need to declare the type of variable that tells Arduino how big a storage location to set
aside for the variable. There are many types available but you'll use just a few;
int
for
the value that has no decimal,
float
for values that have a decimal,
char
for character
variables, and
bool
for values that are just true or false. The second change is adding the
pinMode(led, OUTPUT);
statement. This statement calls the
pinMode
function
and passes
led
and
OUTPUT
to the values in the function's argument.
Now you might be a bit confused because the
pinMode(led, OUTPUT)
function is
nowhere to be found in your code. This is a library function provided by the Arduino sys-