Programming Arduino Getting Started with Sketches


Figure 2-9 Installing the sketches from the book Figure 2-10



Yüklə 5,42 Kb.
Pdf görüntüsü
səhifə15/78
tarix22.12.2023
ölçüsü5,42 Kb.
#189286
1   ...   11   12   13   14   15   16   17   18   ...   78
Arduino SimonMonk 2011

Figure 2-9
Installing the sketches from the book


Figure 2-10
Sketchbook with the book’s sketches installed
Conclusion
Your environment is all set up and ready to go.
In the next chapter, we will look at some of the basic principles of the C language that
the Arduino uses and start writing some code.



3
C Language Basics
The programming
language used to program Arduinos is a language called C. In this
chapter, you get to understand the basics of the C language. You will use what you learn
here in every sketch you develop as an Arduino programmer. To get the most out of
Arduino, you need to understand these fundamentals.
Programming
It is not uncommon for people to speak more than one language. In fact, the more you
learn, the easier it seems to learn spoken languages as you start to find common patterns of
grammar and vocabulary. The same is true of programming languages. So, if you have
used any other programming language, you will quickly pick up C.
The good news is that the vocabulary of a programming language is far smaller than
that of a spoken language, and because you write it rather than say it, the dictionary can
always be at hand whenever you need to look things up. Also, the grammar and syntax of
a programming language are extremely regular, and once you come to grips with a few
simple concepts, learning more quickly becomes second nature.
It is best to think of a program—or a sketch, as programs are called in Arduino—as a
list of instructions to be carried out in the order that they are written down. For example,
suppose you were to write the following:
These three lines would each do something. The first line would set the output of pin 13 to
HIGH. This is the pin with an LED built in to the Arduino board, so at this point the LED
would light. The second line would simply wait for 500 milliseconds (half a second) and
then the third line would turn the LED back off again. So these three lines would achieve
the goal of making the LED blink once.
You have already seen a bewildering array of punctuation used in strange ways and
words that don’t have spaces between them. A frustration of many new programmers is, “I
know what I want to do, I just don’t know what I need to write!” Fear not, all will be
explained.
First of all, let’s deal with the punctuation and the way the words are formed. These are
both part of what is termed the syntax of the language. Most languages require you to be
extremely precise about syntax, and one of the main rules is that names for things have to
be a single word. That is, they cannot include spaces. So, 
digitalWrite
is the name for


something. It’s the name of a built-in function (you’ll learn more about functions later)
that will do the job of setting an output pin on the Arduino board. Not only do you have to
avoid spaces in names, but also names are case sensitive. So you must write 

Yüklə 5,42 Kb.

Dostları ilə paylaş:
1   ...   11   12   13   14   15   16   17   18   ...   78




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin