Cover by Michael Margolis

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

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 analogWrite).

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 ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required