The figure shows the activity on pin
13 while the program is running.
The pin starts in
LOW
state and doesn’t
output any current. We use
digitalWrite
to set it to
HIGH
and let it output 5 volts
for 500 milliseconds. Finally, we set it back to
LOW
for 500 milliseconds and
repeat the whole process.
That’s it! You’ve created your first physical computing project. You’ve written
some code, and it makes the world brighter. Your very own digital version of
“fiat lux.”
17
Admittedly, the status LED doesn’t look spectacular. In Chapter 3, Building
Binary Dice, on page 39, we’ll attach “real” LEDs to the Arduino.
You’ll need the theory and skills you’ve learned in this chapter for nearly every
Arduino project. In the next chapter, you’ll see how to gain more control over
LEDs, and you’ll learn how to benefit from more advanced features of the
Arduino IDE.
What If It Doesn’t Work?
Choosing the wrong serial port or Arduino type is the most common mistake
when doing the first experiments with an Arduino. If you get an error message
such as “Serial port already in use” when uploading a sketch, check whether
you have chosen the right serial port from the
Tools > Serial Port
menu. If you
get messages such as “Problem uploading to board” or “Programmer is not
responding,” check whether you have chosen the right Arduino board from
the
Tools > Board
menu.
Your Arduino programs, like all programs, will contain bugs. The compiler
will detect typos and syntax errors. Figure 6, The Arduino IDE explains syntax
errors nicely, on page 22 shows a typical error message. Instead of
pinMode
,
we called
pinMod
, and because the compiler didn’t find a function with that
name, it stopped with an error message. The Arduino IDE highlights the line,
showing the error with a yellow background, and prints a helpful error mes-
sage.
Other bugs might be more subtle, and sometimes you have to carefully study
your code and use some plain old debugging techniques. (In Debug It! Find,
17.
http://en.wikipedia.org/wiki/Fiat_lux
report erratum • discuss
What If It Doesn’t Work? • 21
www.it-ebooks.info