Visual Output

7.0 Introduction

Visual output lets the Arduino convey information to users, and toward that end, the Arduino supports a broad range of LED devices. (Arduino can also display information with graphical display panels, which is covered in Chapter 11.) Before delving into the recipes in this chapter, we’ll discuss Arduino digital and analog output and explain how Arduino works with light-emitting diodes (LEDs). This introduction will be a good starting point if you are not yet familiar with using digital and analog outputs (digitalWrite and analogWrite) or with using LEDs in a circuit. The recipes in this chapter cover everything from simple single-LED displays to creating the illusion of motion (Recipe 7.7) and showing shapes (Recipe 7.9).

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 or 3.3 volts depending on board) 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 or 3.3 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)

Get Arduino Cookbook, 3rd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.