CHAPTER26

Creating Your Own Library

This chapter discusses how to create your own library. You can find the code downloads for this chapter at http://www.wiley.com/go/arduinosketches on the Download Code tab. The code is in the Chapter 26 download and individually named according to the filenames noted throughout this chapter.

The Arduino project has had an immense success since its creation, and there are several reasons. The cost is, of course, an important criterion to any project. Continuous R & D has also helped, but one of the primary reasons today is simple: the openness of the project. The Arduino community is extremely active. Just look at the Arduino forums: Google+ groups or Arduino events organized in cities throughout the world. This is the community that drives the ongoing evolution of the platform, either by getting the tools to work with new electronic components and breakout boards, or finding and creating their own when nothing exists. In Chapter 25 you created your own shield, now you will create your own library.

Libraries

You can use libraries for several applications, but two main uses exist. One is to have specific routines such as temperature conversion, data processing, or hardware I/O. The second use is to allow the use of specific hardware, hiding away any long routines, and making hardware easy to use. This chapter looks at both of these kinds of libraries.

Library Basics

When you import a library, you import an .h file, the header file. This is a text ...

Get Arduino Sketches: Tools and Techniques for Programming Wizardry 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.