Mastering Arduino
上QQ阅读APP看书,第一时间看更新

Arduino Sketch

When we program the Arduino, the code is put into a project. These projects are called sketches and a sketch is stored in a Sketchbook. A sketch is designed to be as simple and straightforward as possible by abstracting away a lot of the technical aspects of programming the Arduino by using the prebuilt functions.

The coding language used to program the Arduino is very similar to the C programming language. We will be looking at how to program the Arduino in Chapter 6, Programming the Arduino – The Basics and Chapter 7, Programming the Arduino – Beyond the Basics. This chapter is to get you familiar with what sketches are and to look at the tools we can use.

Before a sketch can be uploaded to an Arduino, the Arduino IDE or Web Editor must go through several steps to build the application. The first step to building a sketch is to perform some preprocessing, which turns the sketch into a C++ (see-plus-plus) program, which is passed to the compiler to turn this human-readable C++ code into machine-readable instructions (object files). These object files are then linked against the standard Arduino libraries that provide the basic functionality for the Arduino. The results of this linking are a single hex file that can be uploaded to the Arduino and ran. The nice thing is the Arduino tools perform all of this automatically when we tell them to upload the sketch to the Arduino board.

If we were to put a definition on what an Arduino Sketch is, we would say that it is the project that contains the human-readable code that can be built and uploaded to an Arduino. Now let's look at two tools that we can use to help us write and build these sketches, starting with the Arduino IDE.