Chapter 7. Visual Output
7.0. Introduction
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 (digitalWrite
and analog
Write
).
Digital Output
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 digitalWrite(outputPin,
value)
function to turn something on or off. The function
has two parameters: outputPin
is
the pin to control, and value
is
either 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 Output
Analog refers to levels that can be gradually varied up to their
maximum level (think of light dimmers and volume controls). Arduino
has an analogWrite
function
that can be used to control such things as the intensity of an LED
connected to the Arduino.
The analogWrite
function is not truly analog, although it ...
Get Arduino Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.