Visual output lets the Arduino show off, and toward that end, the Arduino
supports a broad range of LED devices. Before delving into the recipes
in this chapter, we’ll discuss Arduino digital and analog output. This
introduction will be a good starting point if you are not yet familiar
with using digital and analog outputs (
All the pins that can be used for digital input can also be used for digital output. Chapter 5 provided an overview of the Arduino pin layout; you may want to look through the introduction section in that chapter if you are unfamiliar with connecting things to Arduino pins.
Digital output causes the voltage on a pin to be either high (5 volts) or low (0
volts). Use the
value) function to turn something on or off. The function
has two parameters:
the pin to control, and
HIGH (5 volts) or
LOW (0 volts).
For the pin voltage to respond to this command, the pin must
have been set in output mode using the
pinMode(outputPin, OUTPUT) command.
The sketch in Recipe 7.1 provides an
example of how to use digital output.
Analog refers to levels that can be gradually varied up to their
maximum level (think of light dimmers and volume controls). Arduino
that can be used to control such things as the intensity of an LED
connected to the Arduino.
analogWrite function is not truly analog, although it ...