Hardware Reference
In-Depth Information
Outputs can be used to communicate information to a user, make things
move, or send signals to other devices. In this chapter, you will use Galileo's
output functionality to:
• Learn basic Arduino syntax
• Experiment with a few different types of outputs
• Learn basic output functions
• Learn about the difference between digital and analog
• Learn how to send information from Galileo to your computer
Back to Blinking: Digital Output
At the end of Chapter 2 , you connected Galileo to your computer and uploa-
ded example code that caused an LED to blink on and off. Let's take a closer
look at the code, which I've reproduced in Example 3-1 .
Example 3-1. The Arduino Blink Example
int led = 13 ;
void setup () {
pinMode ( led , OUTPUT );
}
void loop () {
digitalWrite ( led , HIGH );
delay ( 1000 );
digitalWrite ( led , LOW );
delay ( 1000 );
}
Setup and Loop
The first thing to notice is that there are two separate blocks of code enclosed
within curly brackets. One starts with void setup() and the other starts with
void loop() . Every Arduino sketch you write will have both of these.
The block of code that starts with void setup() is the setup function . When
your sketch starts, the Galileo will execute each line of code within the setup
function, starting with the first line and then working its way down. It will then
move onto the loop function , which is all the code in the curly brackets after
void loop() . Galileo will repeatedly execute the code in the loop function over
and over again until power is shut down or the reboot or reset button is
pressed. Again, it will execute the code in the order it is written (see
Figure 3-1 ).
Search WWH ::




Custom Search