O'Reilly logo

Mastering Arduino by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Object-oriented programming

Object-oriented programming (OOP) is a programming paradigm that helps us divide our code into reusable components using classes and objects. An object is designed to model something. For example, we could create an LED object that will contain the properties and functionality we want for a LED; however, before we can create an object we need to have a blueprint for it. This blueprint is called a class. Let's see how this works by creating a class that will help us control a LED.

We will start off by creating two new tabs named led.cpp and led.h. The led.h file will contain the definition for the class, and the led.cpp file will contain the code. Let's start off by adding the following code to the led.h file:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required