Turning your class into an Arduino library
A class is a bundle of variables and functions that encapsulates all the code needed for an object of this class to perform certain tasks. The LED blinking example is quite simple to illustrate the core concepts, but you can easily imagine how classes can get much more complex, with many more member variables, functions, and a richer interface. Many parts of examples in previous chapters could be rewritten as classes for future reuse, for example, the PID position controller and the motor driver code.
In the last section, we saw how we can write a class inside our Arduino program and then use it to instantiate many objects of that class, but we have not seen yet how to reuse the class definition in another program. Being able to reuse code across programs, and even share it between different programmers so they can all use it in their programs, is one of the most useful features of OOP in the Arduino ecosystem. For this reason, the majority...