Hardware Reference
In-Depth Information
6. The second required function in all Arduino programs is void loop() .
The contents of the loop function repeat forever as long as the Arduino
is on. If you want your Arduino to do something once at boot only, you
still need to include the loop function, but you can leave it empty.
7. digitalWrite() is used to set the state of an output pin. It can set the pin
to either 5V or 0V. When an LED and resistor is connected to a pin, set-
ting it to 5V will enable you to light up the LED. (You learn more about
this in the next chapter.) The first argument to digitalWrite() is the pin
you want to control. The second argument is the value you want to set
it to, either HIGH (5V) or LOW (0V). The pin remains in this state until it is
changed in the code.
8. The delay() function accepts one argument: a delay time in milliseconds.
When calling delay() , the Arduino stops doing anything for the amount
of time specified. In this case, you are delaying the program for 1000ms,
or 1 second. This results in the LED staying on for 1 second before you
execute the next command.
9. Here, digitalWrite() is used to turn the LED off, by setting the pin state
to LOW .
10. Again, we delay for 1 second to keep the LED in the off state before the
loop repeats and switches to the on state again.
That's all there is to it. Don't be intimidated if you don't fully understand
all the code yet. As you put together more examples in the following chapters,
you'll become more and more proficient at understanding program flow, and
writing your own code.
Summary
In this chapter you learned about the following:
All the components that comprise an Arduino board
How the Arduino bootloader allows you to program Arduino firmware
over a USB connection
The differences between the various available Arduino boards
How to connect and install the Arduino with your system
How to load and run your first program
 
Search WWH ::




Custom Search