Structures

A structure is a user-defined a composite data type that is used to group multiple variables together. The variables in a structure may be of different types enabling us to store related data, of different types, together. The following code shows the syntax of how we would define a structure:

struct name {
  variable list
  .
  .
};

When a structure is defined, the struct keyword is used followed by the name of the structure. The variable list is then defined between the curly brackets.

Let's take a look at how we can create and use a structure by changing the previous sketch, which used the analogRead() function to read the TMP36 temperature, to use a structure. The first thing we need to do is to define a structure that will store ...

Get Mastering Arduino now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.