Hardware Reference
In-Depth Information
You're finally ready to load your first program. Click the Upload button ( ) on
the top left of the IDE. The status bar at the bottom of the IDE shows a progress
bar as it compiles and uploads your program. When the upload completes, the
yellow LED on your Arduino should be blinking once per second. Congratulations!
You've just uploaded your first Arduino program.
BreakingDownYourFirstProgram
Take a moment to deconstruct the Blink program so that you understand the
basic structure of programs written for the Arduino. Consider Figure 1-13. The
numbered callouts shown in the figure correspond to the following list.
Here's how the code works, piece by piece:
1. This is a multiline comment. Comments are important for documenting
your code. Everything you write between these symbols will not be com-
piled or even seen by your Arduino. Multiline comments start with /*
and end with */ . Multiline comments are generally used when you have
to say a lot (like the description of this program).
2. This is a single-line comment. When you put // on any line, the compiler
ignores all text after that symbol on the same line. This is great for anno-
tating specific lines of code or for “commenting out” a particular line of
code that you believe might be causing problems.
3. This code is a variable declaration. A variable is a place in the Arduino's
memory that holds information. Variables have different types. In this
case, it's of type int , which means it will hold an integer. In this case, an
integer variable called led is being set to the value of 13 , the pin that the
LED is connected to on the Arduino Uno. Throughout the rest of the pro-
gram, we can simply use led whenever we want to control pin 13. Setting
variables is useful because you can just change this one line if you hook
up your LED to a different I/O pin later on; the rest of the code will still
work as expected.
4. void setup() is one of two functions that must be included in every
Arduino program. A function is a piece of code that does a specific task.
Code within the curly braces of the setup() function is executed once at
the start of the program. This is useful for one-time settings, such as setting
the direction of pins, initializing communication interfaces, and so on.
Search WWH ::




Custom Search