Creating our own library
If we want to create our own library, we need to learn what kind of files and code make up a library. Every library has at least two files - a header file (its extension is .h) and a source file (its extension is .c
or .cpp
).
The header file contains all the functions of the library. It consists of a number of classes. All header files should include the Arduino.h file in the header file to get access to the standard types and constants of C for Arduino. So, the base structure of the header file is as follows:
#ifndef LibraryName_h #define LibraryName_h #include "Arduino.h" // all the classes for the library goes here....... #endif
We now need to save the header file as LibraryName.h
.
Now, let's see the .c
or .cpp
file's structure. The .cpp
file includes two headers. One is Arduino.h
and another is our header file that we just made (LibraryName.h
). The .cpp
file then contains the functions of our main code just LibraryName::
in front of every function...