Hardware Reference
In-Depth Information
DS1631(DEV4),
DS1631(DEV5),
DS1631(DEV6),
DS1631(DEV7)
};
This code initializes all of the possible DS1631 I2C devices and can be used to monitor all eight possible sensors.
You can access sensor four by calling TmpSense[4].getTemp() . You can use a for loop to read through the array and
obtain all the sensor values. Lastly, in order to get the most from the library, you must document how the device
names are defined; otherwise, users of the library will have to examine the header file and deduce all of the features.
Another benefit of using libraries is to organize convenience functions like Fahrenheit conversion as shown in the
loop code in Listing 12-13. A good follow up exercise is updating the library to support getTempC() and getTempF() .
One benefit of using Listing 12-12 is that we abstract away the details of configuring the temperature sensor,
making the main sketch code simpler; we only need to configure and use the device. The library and the object
contain all the code that are typically cut and pasted into the main sketch. This allows the user to avoid major
headaches by using the temperature sensor instead of debugging the code.
Summary
Arduino libraries are powerful tools for sharing code between projects and users. This code is organized for bundling
and easy distribution. In this chapter we showed how to create libraries in a specific sketch directory. You can now
choose whether to write C style libraries or C++ object based libraries. Then, we explained how to convert that
directory into an Arduino wide library. The Motor controller evolved from a single sketch to a powerful library with
many helpful commands that control a robot or a set of motors. The other major example shows how to interact with
devices using the I2C protocol and makes those devices easier to access and use. We also reviewed the steps necessary
to take a library from a single project and make it available to all of your code system-wide. The next steps are to check
your library code into GIT and share the project with other Arduino users as we described in Chapter 2.
 
Search WWH ::




Custom Search