Using, Modifying, and Creating Libraries
16.0 Introduction
Libraries add functionality to the Arduino environment. They extend the commands available to provide capabilities not available in the core Arduino language. Libraries provide a way to add features that can be accessed from any of your sketches once you have installed the library.
The Arduino software distribution includes built-in libraries that cover common tasks. These libraries are discussed in Recipe 16.1.
Libraries are also a good way for people to share code that may be useful to others. Many third-party libraries provide specialized capabilities; these can be downloaded from the Arduino Library Manager but also from GitHub. Libraries are often written to simplify the use of a particular piece of hardware. Many of the devices covered in earlier chapters use libraries to make it easier to connect to the devices.
Libraries can also provide a friendly wrapper around complex code to make it easier to use. An example is the Wire library distributed with Arduino, which hides much of the complexity of low-level hardware communications (see Chapter 13).
This chapter explains how to use and modify libraries. It also gives examples of how to create your own libraries.
16.1 Using the Built-in Libraries
Problem
You want to use the libraries provided with the Arduino distribution in your sketch.
Solution
This recipe shows you how to use Arduino library functionality in your sketch.
To see the list of available libraries ...
Get Arduino Cookbook, 3rd Edition 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.