Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

Programming Arduino (1) Pages 44

Uploaded by

axl1994
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Programming Arduino (1) Pages 44

Uploaded by

axl1994
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

loop functions.

As you know from the Blink example that you ran in Chapter 2 ,
you have to have some “boilerplate” code, as it is called, before you can add
your own code into a sketch. In Arduino programming the “boilerplate” code
takes the form of the “setup” and “loop” functions that must always be present in
a sketch.
You will learn much more about functions later in the book, but for now, let’s
accept that you need this boilerplate code and just adapt your sketch so it will
compile (see Figure 3-4 ).

Figure 3.4 A sketch that will compile .

The Arduino IDE has looked at your efforts at writing code and found them
to be acceptable. It tells you this by saying “Done Compiling” and reporting the
size of the sketch to you: 450 bytes. The IDE is also telling you that the
maximum size is 32,256 bytes, so you still have lots of room to make your
sketch bigger.
Let’s examine this boilerplate code that will form the starting point for every
sketch that you ever write. There are some new things here. For example, there
is the word void and some curly braces. Let’s deal with void first.
The line void setup() means that you are defining a function called setup . In
Arduino, some functions are already defined for you, such as digitalWrite and
delay , whereas you must or can define others for yourself. setup and loop are
two functions that you must define for yourself in every sketch that you write.
The important thing to understand is that here you are not calling setup or
loop like you would call digitalWrite , but you are actually creating these

You might also like