Hardware Reference
In-Depth Information
Figure 3-1. The structure of every sketch starts with a setup and loop func-
tion. The code in the setup function is executed once at the beginning of
your sketch, and then code in the loop function executes over and over
again.
To summarize, when an Arduino sketch runs, it will:
• Execute the code in the setup function once.
• Then it will execute the code in the loop function over and over again.
Variables
Now you may be eyeing the line that says int led = 13; right before the setup
function in Example 3-1 . That line is creating a variable , a place in memory to
store data. In this case, you're storing an integer , which is a whole number.
This line gives this spot in memory a name ( led ) and stores the value 13 in it.
A variable is like a locker to store data. At any point in your sketch, your code
can open the locker to access the data inside, or it can replace that data with
other data. int led = 13; means that your code is creating a locker with the
label led and it's going to hold integers (as opposed to other types of data
such as floating point numbers or text). It's also going to put the value 13 in
that locker.
If you jump down further in the code, any spot where you see led is where
the sketch will be accessing that number 13 from memory.
Search WWH ::




Custom Search