Hardware Reference
In-Depth Information
value : either HIGH or LOW
digitalWrite() does not return a value. Again, I'll cover return values in
Chapter 4 .
Therefore, within the Blink sketch, digitalWrite(led, HIGH); sends 5 volts
to pin 13, illuminating the LED.
And digitalWrite(led, LOW); connects pin 13 to ground, turning off the LED.
delay()
Your code will run very quickly, so if you only turned the pins on and off in the
loop function, there won't be enough time to see the LED fully on or fully off
and it'll simply appear dim. Therefore, you need to tell Galileo to wait for a
second after turning it on and again after turning it off.
To do that, you'll use the Arduino function delay() , which stops your program
in its tracks for the amount of milliseconds that you specify.
The syntax of delay() is:
delay(ms);
The parameter of delay() is:
ms : the number of milliseconds to wait
delay() does not return a value.
In the case of the Blink sketch, delay(1000); tells Galileo to wait for 1 second
(1,000 milliseconds) after setting pin 13 high and again after setting it low.
Code and Syntax Notes
Now that you've walked through each line of code in the Blink sketch, let's
discuss some of the details when it comes to code.
Semicolons
You probably noticed that many lines of code have a semicolon at the end.
This is called a terminator and it lets the Arduino compiler know that it has
reached the end of a statement . In programming, a statement is like a sen-
tence and in Arduino syntax, the semicolon is like the period at the end of a
sentence.
There are some cases when you don't use a semicolon, such as when you're
opening a block of code. You'll see in this in the Blink sketch with the lines
that start the setup and loop functions. You also do not need a semicolon
after the curly bracket that closes a block of code.
Search WWH ::




Custom Search