Book Image

Learning C for Arduino

By : Syed Omar Faruk Towaha
Book Image

Learning C for Arduino

By: Syed Omar Faruk Towaha

Overview of this book

This book will start with the fundamentals of C programming and programming topics, such data types, functions, decision making, program loops, pointers, and structures, with the help of an Arduino board. Then you will get acquainted with Arduino interactions with sensors, LEDs, and autonomous systems and setting up the Arduino environment. Moving on you will also learn how to work on the digital and analog I/O, establish serial communications with autonomous systems, and integrate with electronic devices. By the end of the book, you will be able to make basic projects such as LED cube and smart weather system that leverages C.
Table of Contents (17 chapters)
Learning C for Arduino
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

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 name and _pin instead...