Programming Arduino Getting Started with Sketches



Yüklə 5,42 Kb.
Pdf görüntüsü
səhifə22/78
tarix22.12.2023
ölçüsü5,42 Kb.
#189286
1   ...   18   19   20   21   22   23   24   25   ...   78
Arduino SimonMonk 2011

Experiments in C
You need a way to test your experiments in C. One way is to put the C that you want to
test out into the 
setup
function, evaluate them on the Arduino, and then have the Arduino
display any output back to something called the Serial Monitor, as shown in 
Figures 3-5
and 
3-6
.
The Serial Monitor is part of the Arduino IDE. You access it by clicking on the
rightmost icon in the toolbar. Its purpose is to act as a communication channel between
your computer and the Arduino. You can type a message in the text entry area at the top of
the Serial Monitor and when you press Return or click Send, it will send that message to
the Arduino. Also if the Arduino has anything to say, this message will appear in the
Serial Monitor. In both cases, the information is sent through the USB link.
Figure 3-5
Writing C in
setup


Figure 3-6
The Serial Monitor
As you would expect, there is a built-in function that you can use in your sketches to
send a message back to the Serial Monitor. It is called 
Serial.println
and it expects a
single argument, which consists of the information that you want to send. This information
is usually a variable.
You will use this mechanism to test out a few things that you can do with variables and
arithmetic in C; frankly, it’s the only way you can see the results of your experiments in C.
Numeric Variables and Arithmetic
The last thing you did was add the following line to your blinking sketch to increase the
blinking period steadily:
Looking closely at this line, it consists of a variable name, then an equals sign, then
what is called an expression (
delayPeriod + 100
). The equals sign does something called
assignment. That is, it assigns a new value to a variable, and the value it is given is
determined by what comes after the equals sign and before the semicolon. In this case, the
new value to be given to the 

Yüklə 5,42 Kb.

Dostları ilə paylaş:
1   ...   18   19   20   21   22   23   24   25   ...   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