Programming Arduino Getting Started with Sketches



Yüklə 5,42 Kb.
Pdf görüntüsü
səhifə45/78
tarix22.12.2023
ölçüsü5,42 Kb.
#189286
1   ...   41   42   43   44   45   46   47   48   ...   78
Arduino SimonMonk 2011

6
Input and Output
The Arduino
is about physical computing, and that means attaching electronics to the
Arduino board. So you need to understand how to use the various options for your
connection pins.
Outputs can be digital, which just means switched between being at 0V or at 5V, or
analog, which allows you to set the voltage to any voltage between 0V and 5V—although
it’s not quite as simple as that, as we shall see.
Likewise, inputs can either be digital (for example, determining whether a button
pressed or not) or analog (such as from a light sensor).
In a book that is essentially about software rather than hardware, we are going to try and
avoid being dragged into too much discussion of electronics. However, it will help you to
understand what is happening in this chapter if you can find yourself a multimeter and a
short length of solid core wire.
Digital Outputs
In earlier chapters, you have made use of the LED attached to digital pin 13 of the
Arduino board. For example, in 
Chapter 5
, you used it as a Morse code signaler. The
Arduino board has a whole load of digital pins available.
Let’s experiment with one of the other pins on the Arduino. You will use digital pin 4,
and to see what is going on, you will fix some wire to your multimeter leads and attach
them to your Arduino. 
Figure 6-1
 shows the arrangement. If your multimeter has crocodile
clips, strip the insulation off the ends of some short lengths of solid core wire and attach
the clip to one end, fitting the other end into the Arduino socket. If your multimeter does
not have crocodile clips then wrap one of the stripped wire ends around the probe.


Figure 6-1
Measuring outputs with a multimeter
The multimeter needs to be set to its 0–20V direct current (DC) range. The negative
lead (black) should be connected to the ground (GND) pin and the positive to D4. The
wire is just connected to the probe lead and poked into the socket headers on the Arduino
board.
Load sketch 6-01:


At the top of the sketch, you can see the command 
pinMode
. You should use this
command for every pin that you are using in a project so that Arduino can configure the
electronics connected to that pin to be either an input or an output, as in the following
example:
As you might have guessed, 

Yüklə 5,42 Kb.

Dostları ilə paylaş:
1   ...   41   42   43   44   45   46   47   48   ...   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