Hardware 5
Hardware
These are two functions that are the basic structure of Arduino programming. A function is a piece of code
that does something.
The rst function is ‘setup’. The word “void” before it just tells you that it doesn’t return anything or give
something back. The ‘setup’ function is what the microcontroller knows to do rst. Anything you put in be-
tween the rst two brackets{} will be done rst.
The second function is ‘loop’. It also doesn’t return anything. Theloop function happens right afterset-
up, and runs over and over, until you reset the microcontroller or load a new program.
Without you telling the microcontroller to do something dierent, it will run:
setup
loop
loop
loop
loop
...
That’s how the microcontroller works. If you program something else, it might be dierent.
The sentences that are after the two forward slashes (//) are called comments. They are used by the
programmer to remember what they were doing. The microcontroller completely ignores anything after the
two slashes on the same line. It is always good practice to comment in your code, because it is often hard
to remember what you were doing, or other people might need to look at your code and gure out what you
were trying to do.
1.4: Using pinMode
The program that opens up when you start the IDE automatically doesn’t do anything. You, the programmer,
has to type something to make things happen. For this example, we want to tell the Galileo to blink the light
emitting diode (LED) that it has on board (Lesson 1, Figure 3).
Lesson 1 Figure 3