Вы находитесь на странице: 1из 129

HROUIHO .

MASSIMO BANZI

GETTING STARTED UUITH ARDUIND

F irst E d itio n
O'Reilly
Beijing, Cambridge, Farnham, Koln, Sebastopol,Tokyo

ARDUINO

!

2012
004.3
32.96
23

.
23 Arduino / . . .: ,
2012. 128 . ( ).
ISBN 978-S-4252-0631-2
Arduino, ,
-, -
, .
Arduino
,
.
Arduino , -
, .
, ]
!
004.3
32.96

ARDUINO

.
. . .
. . .
. . .


, . , 17, . 1, . (495) 788-0075 (76)

14.01,2012. 60x90/16.
. . . 8,0. . . 2 000 . 5679.


144003, . , , . , . 25

, 2012
. ., 2012
ISBN 978-5-4252 0631-2 . 2008, Massimo Banzi
Authorized translation of the English edition of Getting Started with Arduino, 1st Edition
ISBN 9780596155513. This translation is published and sold by perm ission of O'Reilly Media, Inc., the
owner of all rights to publish and sell the same.
Getting Started with Arduino, 1-
ISBN 9780596155513. O'Reilly
Media, Inc., .

Arduino ................................ :.... ;................................................... . . . 7

.......................................... ................................................. .................................................... ...8


................................. ...............................................................................................................12
.............................................................................................................................. ......13

1. ....................................................................................................................................... .15
...........................................................;..........................................................................16
?..................................... ................................................... .17

2. Arduino................................................................................................................ .19
..................................................... .......................................................................................20
..........................................................................................................................................................,21
...................................... . ..........................................,22
............................................ .......................................................................24
.........................................................................................................................................26
!........................i............................................................................................ ...........28
!..................................................................................................................................29
........................................................................................................... .............................. . .30

3. Arduino......... .......................................................................................................31
Arduino................................................................................................................31
(IDE)......................................................................... ................................34
Arduino.................................................................................................................................. .34
: Macintosh......................................................................................................... .35
: Windows..............................................................................................................36
: Macintosh................................ .....................................................................37
: Windows..................................................................................................... .. .38

4. Arduino.......................................................................... .41
..................................................... .........................................41
............................................................................................42
..................................................................................... .42
, ...............................................................................................46
Arduino .............................................................................................................................47
......................................................................... .47
I ] , ...........................................................................................................48
?.................................................................................................................................. ........51
?,...................................... ..................................................................................52
.............................................................55
?.......... :.................. .............................................................................................................58
................................ .................... ,58
5 . ........................................................................ 65
/.................................................................................... 65
- ................................... 68
..:.......................................................................... 75
........................................................................................................................................76
................................................................................................80
.................................................................. 80
(,
)..............................................................................................82
.................................................................. 85

6. , ................................................................................................. 85
...........................,.......................................................................................... ........................ 87
..................................... *................................................................................................88
....................................................................................................... ....... ...............(................. 96
.............................................. 97

7 . ......................................................................................99
........................... 99
..................................................................................................... ,...........................1 00
, ......................................................... .....101
,............ ...................................... 102
................... 102
.................................................................................................................................103

. ..... ..............................................................................................1 07

. .........................................109

, Arduino....................................... ;......................111

, ............................................... ................... 127

Arduino
Arduino


O'Reilly
,
.
800-998-9938
corporate@oreilly.com.

O'Reilly
O'Reilly Media. Make: Projects ( :
)
O'Reilly Media. ,
,
.

.
,
.
, ,
,
,
, .

.
.


, . O'Reilly Media
,
.
,
, Arduino,
, , .

O REILLY*
Make

Arduino 7


.
,

.
, ,
, . ,
. ,
, , ,
.

, , ,
(
). :

,
.

, ,
.

:
, . ,
.

,
.

. ,
, ,
, ,
.

, ,
. ,
.
, ,
.

8
.
.
,
.
.
: ,
,
.


, ,
, . ,
,
70- .
, .

,
, ,
, , ,
.

,
.
,
, .
.
,
,
60- .

,
, . ,
.

, ,
, , ,
.

,
,
,
. tinkering
(). ,

9
, . ,
(Nouvelle Vague),
. , ,
, -
-.

-, ,
, .
, .
, .
, - .

.

,
, , .

, .

(www.exploratorium.edu/tinkering)

,
, ,
, .

1982
.
, .


.

,

,
,
,
, , .

, ,
.



ZX81 . ,

10 Arduino
,
, , -
. ,
,
.

,
, .

, .

11

,
Arduino: , , -
.
.

, , , ,
Arduino .

, .

, , -
, .

, ,
, ,
:

-, , ,
, , ,
, , , ,
, , , ,
, , , -
, , , , -
, , , , -
, , , ,
, , , -
, , , , -
, , , ,
, , , , ,
, , , ,
, , , ,
, .

12 Arduino

,
, , - .
,
. , ,
.

, , , ,
. ,
.

Maker Media

1005 Gravenstein Highway North

Sebastopol, CA 95472

(800) 998-9938 ( )

(707) 829-0515 (/)

(707) 829-0104 ()

Maker Media O'Reilly Media,



, ,
.

Make, Craft, Maker Faire, Hacks,


Make: Projects DIY Science, Maker Media
,
.

Maker Media . :

ww w.makezi ne.com
CRAFT: www.craftzine.com
Maker Faire: www.makerfa ire.com
Hacks www.hackszine.com

bookquestion@
oreilly.com.

13
- O'Reilly , Getting Started with
Arduino, ,
.
www.makezine.com/getstartedarduino.

. -
O'Reilly www.oreilly.com.

Arduino,
www.arduino.cc.

14 Arduino
'!.

Arduino ,
-
,
Processing,
Java (www.processing.org).

Arduino

,
.
Processing
Flash, VVVV Max/MSP.
Arduino ,
.

(IDE, Integrated Development Environment)
- www.arduino.cc.

, , Arduino
:

;
Windows, Macintosh Linux.

Processing;

.

USB-
, .
,
.

15
. ,
,
,
Arduino.

, Arduino, . USB-
20 , - 5 .
.

,
, .

Arduino ,
,
.

,
Arduino
.

Arduino,
, ,
.
, . ,

. , ,
, ,
, .
.

Arduino ,
, Wiring.

Arduino
, ,
, -
,
. , , -, -

16 Arduino
, ,
.

Arduino
, ,
.
,
:




, . ,
, ,
,
.
,
.
,

, ,
.

, Arduino,
.


,
,
, .

-
I ,
.
, ,
. -

17
,
.
,
,
.

Arduino .

, ,
,
.

Arduino

,
.

18 Arduino
2 . Arduino

Arduino
, .


.


.
-
. ,
Arduino, , ,
, - , , .

, .
,
. -
,
,
.

It , ,
Arduino.

Ard u] 19

Arduino .
,
, .
, .

, , ,
. .
, , -
,
. , -
- , .


. , ,
, , -,
,
,
,
?

, 5127 ,
{www.international.dyson.com/
jd/1947.asp).

20 Arduino

I ,

, - .

11
.
, ,
,
- .

Arduirto 21


.

. , ,
,
. Myra
,
.
.

. ,
, ,
,
.

,
, .


, Max, Pure Data W VV.
,
,
.
,
,
,
, , ,
..

22 Arduino
Arduino 23

,
, . ,

. ,
,
!
,
1966 , - ,
,
. ,
, ,
, .

24 Arduino
SC n s f
tth esr
f i m
R o c k V | R o ~l.
*

11 anx*Ki is wsr rk rcad. . . lt* m eo**x*i rir <kjje nm-i**.

, !

Hi i1 . -

-.

I ! ,
. .

Arduino 25

26
60 , -
1.110 . -
, -
( , : ,
< < .
, .

< ,
, -
| , .

. ,
,

, ,
.
, , .

11
, , , -
. -
( , .

(
.

Arduino 27
!

:
, , ,
.
,
, , .
, -
Olivetti. Arduino.

, Olivetti
60- , 90-
, .
- ,
.
, ,
, .

,
- .
, -
.

28 Arduino
!

imiui 1 ,
,
. -
( -

,
,

(I ,
, ,
! ,
.

<(
(Low Tech Sensors and Actuators)
Vi -. , -
1< , ,
.

Arduino 29


Arduino. www.arduino.cc
.
Arduino
,
.

,
Playground ( ) [www.arduino.cc/
playground],
.

,
.

Arduino
, .

30 Arduino
3. A rd u in o

Arduino :
, -
11 ,
( (IDE)
, . -
-
11 I ,
t. Arduino.
, .
I 1 -
/||||||' ,
, , -
IU ., , . .
, -
11(410(1. ,
Ml .
| hi , -
||)0 -
", .

, ,
11 . -
ma i I ill ,
, -
. , .

Arduino
Alillllno ,
, , ,
, , ,
. Arduino
:
II iiBnilli .

Arduino 31
Arduino, 28
ATmega168.
,
.
Arduino.
Duemilanove
.
, Arduino Uno,
Arduino Diecimila Arduino NG, . 3-1
Arduino Duemilanove, . 3-2 Arduino NG.
, Ardui.no,
. , ,
.

14 - ( 0-13}
, ,
,
.

( 0-5)
,
0 1023.

( 3 ,5 , , 9,10 11)
,
.
,

.
USB- ,
USB- ,
9 .
2,1 , .
, USB-
.
, .


Arduino NG Arduino Diecimila, , EXT ()
USB PWR_SEL,
USES-,

32 Arduino
tSDL
agn A r d u a n o 7"1
*
G3B4X D u e r o ila n o v e ,,
- - i-
COIOIOIOJ
C0D
a


<
0 =/
W U U .< ?rd u ln o .C C
9 P SJU E ft A r ^ t ,08
a raS'U land ijin 0 1 2 3

, 3-1, Arduino Duemilanove

1AlillllllU/HH'iiojimoCmiKoH
Arduino 33
(IDE)

(IDE, Integrated Development


Environment), ,
Arduino Processing (www.
processing.org). ,
.
(
) avr-gcc.

,
Arduino. ,

.

Arduino, ,
:

USB- .

,
.

USB-
,
.
, .

Arduino Linux
. , . www.
arduino.cc/playground/Learning/Linux.

Arduino

Arduino
(IDE) - www.arduino.cc/en/Main/Software.
.

,
.
-[], arduino-0012. -

34 Arduino
Ill . : , /Applications (
'. Mm ) C:/Program 5( Windows).
||'|)||, KOI ,
| |||||11| arduino Arduino. -
. , ,
iii.ni. .

|)|11|
1 1 ihti 1 Arduino, . 7,
" . || .

iHiii'pii ,
| 1(.< USB-.

V< : Macintosh

in Drivers () arduino-0012 -
FTDIUSBSerialDriver_xJix_x.dmg.
!>< ,
I in lll*lMlicii<ilDriver_v2___2_9Jntel.dmg).
dniij, .

|1(111#
I in , lyoie Mac Intel, MacBook, MacBook Pro, MacBook Air, Mac Pro no-
. i|iiin|||||ii|i ,i Intel Mac Mini iMac, , -
mini I Intel, sFTDIUS85erialDriver_v2._2_9Jntel.dmg.
) | * Intel .

|
I 11 ill I'.USnrlalDriver, .
, ,
. -
. , ,
. .
1|<* PWR (), -

I . . , . 7, -
|||' .

Arduino 35
: Windows

Arduino .
Found New Hardware Wizard ( ),
Windows
Windows Update ( Windows).

Windows
Windows Update. No, not this time (, )
Next ().

Install from a list or specific location (


) Next (
).

Include this location in the search (


), Browse (), ,
Arduino, Drivers.FTDI USB Drivers .
, Next ().

Windows Vista -
Windows Update. ,
Drivers\FTDI USB Drivers.

,
, ;
,
.


Arduino.

, '
Arduino.
. '
.

36 Arduino
<11 : Macintosh

II i - I. Arduino ,
liinl'. Serial Port, , -
|1) /dev/cu.usbserial.
11*|( Arduino. . 3-3 .

|||1 III' ton sketch Help


Auto Format
Copy for Forum
Archive Sketch

Board
I i ' I III , ll I jil 1Jig L.ED
7dev/cu.usb^nal-A7007xQS:
* I I|||* III) n Burn Bootloader /dev/tty,Seriai?ort-I
/dcv/cu.SeriaiPort-1
1.1 atluiK) /dev/tlyJep9S-DataTransfer-l
I /dev/cuJep95-DataTransfer-l
iiIiiMi.l(l1, Otl CUT)i // a c ts the d ig it a l
/dev/tty .Bluetooth-Modem
// pin as outpot
| /dev/cu.3tuetooth-Modem
/dev/tty. Bluetooth- PDA-Sy n c
il.l I m ii O /dev/cu.Bluetooth-PDA-Sync
ST I-
..... l u l l III, III Oil); / / turns the LED on
la | ML ( k ) |
ai>i. iin. iu iit d , i oioi
/ / melts for a second
/ / turns the LED off *f
>11.1M
LI 111)| / / 5 0 U 3 for a second

. 3-3.
Arduino

Arduino 37
: Windows

Windows
, . ,
Start (),
Computer () Vista computer ( )
Properties ().

Windows Hardware ()
Device Manager ( ). Vista
Device Manager ( ).

Arduino , Ports ( & LPT)


[ ( & LPT)]. Arduino
USB-, , COM3, . 3-4.

. 3-4. Windows,

38 Arduino
|||1'1||1!
llii h i ... .. 0 11 1 1 !| Windows , 9. -
h iiiii /linn iiertoiopiiie , Arduino . -
in uni . ii|Hi(liii'My, 7, .

. in1 m in ,
...... tools > Serial port ( > ) -
1| 1||111 Arduino.

Ii'iinpii Arduino -
I hi I (.

Arduino 39
4.
Arduino

| 10/1 ,
(||)<11110 .

1 niiM'hiiil, Arduino,
|<||11 > .

1<* , -
-
111<| iMl , -
.
v* 11 , ,
.
iliiiu -
I ||||||< ( -
| , .

Sese/Perceive

1,1 . 4-1.

Arduino 41


,
.


. -
,
.
, ,
,
. ,
, .
,
,
,
.
, .

, ,
, ,
, , ,
.
,
. -
, , , ..

,
.

, Arduino
,
.
,
.

,
,
,
.

42 Arduino
Arduino ,
>.
, , . 4-2.

( ), .
( ), .

,
Arduino, . ,
,
.

,
Arduino.
Arduino, .

. 4-2. Arduino

Arduino 43
File > New ( > ),
,
Arduino. Blinking__LED .
, 4-1, Arduino (
).
www.makezine.com/getstartedarduino.
, . 4-3.
- ... - * ' . ' --.'..-';: ?
4-1.
#define LED 13 //
/ / ' 13
void setup

' . ...
pinMode(LED, OUTPUT); //
//
} -/~
void loop()
{
digitalWrite(LED, HIGH); //
delay (1.000) ; //
digitalWrite(LED, LOW); //
delay (1000); //

, ,
, . Verify
() ( . 4-3 ). ,

Done compiling ( ).
,
, ( -
Windows - ).

. Upload to I/O Board


( -) (. . 4-3).
,
USB-. , ,

, .

44 Arduino
Upioad to I/O board

^ d efin e LED 13 / / LED connected to


t / d i g i t a l p in 13

void 3etup()
{
p in tlcde d ED , OUTPUT):-;
+-

vo id loopO
{
d lg lt a lW r it e (L E Q , HIGH); U tu r n s th e LED on
d e la y(1 0 0 0 ); // w a it s fo r a second
d lg it a iU o it e fL E D , LOW); // tu rn s the LED o f f
d e la y ! 1008); // a it s fo r a second
)

---- Your skech goes here


. 4-3. Arduino

,
,
Done uploading ( ),
.

RX
, ,
.

Done uploading
, ,
. ,
(. 3), Tools >
Serial Port ( > ). ,
Tools > Board ( > ), ,
Arduino.

Arduino 45
, 7,
.

Arduino,
,
. , ,
.
.

, L
, .
. 4-2, .

, ,
. Arduino
.

, Arduino , ,
- .

(1DE), ,
, .

, , ,
. , , Arduino
, .
, .., ,

QuickTime Player Windows Media Player.

,
,
. ,
- .
. , :
, , .
, ,
. - ,
, .
- Arduino,
, ,
, .

46 Arduino
, ,
{
}, .
, ,
vo id setup (),
.
, Arduino
,
void passTheParmesan ,
Arduino.
.
? .
passTheParmesan{), Arduino
, , ,
, .

Arduino
Arduino :
setup ( ),
loop ().
setup () , ,
,
loop () , .
, Arduino
. -,
, -, , Arduino,
.
.
, .


,
//, Arduino .
, ,
,
, , .
- ,
.

Arduino 47
, ,
, : !
! (- ,
). , -
:
. ,
. : ...
, ! -?

, , ,
,
.

, ,
,
( )
.
.

,
, , .

// 01 :

,
. ,
, , ( 4-1)
.

#define LED 13 //
// 13
#define
. Arduino
13 , LED.

(, , Verify
Upload to I/O Board. ,
.)

, Adeline , (LED),
, 13 Arduino.

48 Arduino
voidsetup()
Arduino,
s e tu p () .

{
pinMode(LED, OUTPUT); //
//
! p in y Arduino,
. ,
i n p u t (),
OUTPUT ().
,
.

, pinXode , ,
, , in pu t o u t p u t
Arduino . , ,
,
.
}
se tup () .

void l o o p ()
{
loop () ,
. ,
.
digitalWrite(LED, HIGH); // (LED)
, , digicalWrite ()
( ) ,
o u t p u t (). (
l e d ), (
, l e d - , 13-
). (h i g h )
(l o w ) .

,
, , .
230 , 110 , Arduino
5 .

Arduino 49
,
. digitaiwrite ()
5 , .
,
- ,
.


,
, .
.
d e l a y (1000); //
, Arduino -
. , ,
, ,
. delay ( ) ,
,
,
. ,
1000 1 . ,
.
digitalWrite(LED, LOW); // (LED)
(l e d )
. h i g h () l o w (
)? ,
, h i g h , Arduino
5 . l o w 0 .
: o n ( .) o f f ( .).
d e l a y (1000); //
, ,

.

}
loop.

,
:
13 ( );
loop;

50 Arduino
(LED), 13;

(LED), 13;

loop.

, . ;
, ,
.

, ,
. ,
,
. ,
,
, , .
-
.

?

. , ,

.

Arduino ,

,
.


. , ,
Arduino.

Arduino 51
?
- , ,
, . .
,
, .
. , ,
, ,
(. 4-4).

52 Arduino
,
, .

? ,
, ,
. , ,
.

, . 4-5,
: ( )
, (
,
).

,
, .

. ,
.
, ,
. ,
.
, ,
, .

53
.
, ,
, ,
, , , . ,

, .

, ? ,
, , ,
, ,
, .

,
. ( ,
),
( ) ().
( ),
( ), ( ),
( ) .

, 9 ,
, ,
.

, ,
.

,
,
- ,
.
, :
() ;
()
.

, ,

. ,
,
. ,
, ,
, ,
.

54 Arduino
, .
9 . ,
, ,
. :
(
), ,
,
.

/ () = V () / R ()

, , .
,
.



, ,
,
. ,
.
, Arduino .
.

: .

, , :
, ,
, .
, ( ).
, .

Arduino
digicalRead () , , -
, .
h i gh ()
LOW ().

, , ,
, ,
. ,

Arduino 55

.
d ig ita lR e a d () Arduino
, -
.

, . 4-6. ,
,
.

.
www.amperka.ru/breadboard. (. - -
.)

.
www.amperka.ru/jumper-wires

. 4-6.

56 Arduino
10 . www.
amperka.ru/resistors

.
www.amperka.ru/button

,
,
.

,
:

4-2.
tdefine LED 13 //
f.define BUTTON 111 ,
/, . //
int vai; -0; //
.val '-
^4/ ' // '
'-
..
- '--- V,
void setup {
pinMode(LED, OUTPUT); // Arduino,
/./ .. "(LED) ,'
pinMode(/ INPUT); // BUTTON
} . > ' ' /
void, /loop ():{
vai-~ digit'alRead (BUTTON) //

// , -j:
// HIGH ( ),
if (val == HIGH) {
'; . ; -- - - - ;
.digitalWrite (LED, HIGH); //.
) '.else (;
"digitaiWnte (LED, LOW);; '
- T.V :
;I:j/MSc
> - : : -! T

Arduino 57

File > New ( > ) (
, ). Arduino
,
PushButtonControl. (
www.make2ine.com/getstartedarduin0
) 4-2. ,
.

?
: ,
, if.

if, , ,
( , Arduino )
. if
, ,
.
, else.
, ==
=. ,
t r u e f a l s e . .
. ,
, ,
. , 25
- .
. ,
, . ,
? .




.

, .
, , ,
, .
, , ,
, .

S3 Arduino
,
. ( ,
.) , Arduino,
. , ,
,
-. Arduino :
, (,
- ), , ,
.

ir.t val = 0;
ir.t , , val
= 0
, .

,
- :

val = 112;
112.

, Arduino , # define, .
, Arduino, ,
, , .
, , # de
fine. # define ,
.

val
digitalReadO. ,
Arduino ,
,
. ,
, (
, RAM). ,
, , .
, ,
.
-, ,

Arduino 59
.
.

, ,
(l e d )
.

, , 4-3:

4-3.

#deiine LED 13// (LED)
jfdefine BUTTON 111 ,
// -
int val = 0; // val
//
int state = 0; // 0 = LED ,
// ' 1 = LED
void setup() (
pinMo'de (LED, OUTPUT); //. Arduino,
// (LED)
pinMode(BUTTON, INPUT); // BUTTON ()
/
> % . ' '" ' ...
void loop(> {
val = digitaiRead(BUTTON); //
//
// ,
// HIGH ( )
if (val == HIGH) {
state = 1 - state;
) - .. ; ,
if (state == 1) {
digitalWrite(LED, HIGH); II (LED)
} else {
digitalWrite(LED, LOW);
}

60 Arduino
, , ...
. , , ,
.

: s t a t e
, 1
, .
{ ).

,
(v a l = h ig h ), I .
,
, , 1 - 0 = 1, 1 - 1 = 0:

state = 1 state;
, ,
, . =
, ,
, .
1 .

, s t a t e ,
, .
, .
- .

, Arduino .
1 , ,

. , , Arduino

s t a t e . ,
, ,
, , .
, ,

, , .

?
,
. :
val .

,
h i g h l o w .

Arduino 61
4-4 :

4-4.
.
!
Ide/irie LED lit /./ (LED)
:?//!.(Gp* lUTT/if iff -
/// ...
Got; val = 0; // val /
If .
int old_val = 0;>://
!: "val"
int state = ! // 0 = LSD
// 1 = LED '.; . -
void setup() (
" ;pint-lode (LED, OUTPUT) ; // ' Ardui.no,
// :(LED)'
pinMode (BUTTON, INPUT),- /7 BUTTON ()
.// .
5
void loop { 7. '3'.' / " " :
val = digital Read (BUTTON) ; // ^
/ .; // ..

.//,

// ,
if ( (val *== HIGH) St (old_val == LOW)) {
V' : state *> 1'- state;

old_val = yai;; //.val ,


if (state 1) {
digi talWrit'e'(LED, HIGH) ; //
j else {
digitalWrite(LED, LOW);
}
G. ' \\ ' : ,

62 Arduino
, , .

? ,
, .
: ,
. , ,
. ,
. ,
,
.

, Ardulno
.
,
10-50 ,
.

4-5 :

4-5.
.
!
!
fdefine LED 13 // (LED)
-fdefine BUTTON 7 // ,
* //
;int val = 0; 7/ val
//
int old_val = 0; //
// "val"
-
in t state: 0; // 0 = LED
// i = LED
void setup() { 7:
pinliode (LED, OUTPUT).; // Ardulno,
// {'LED)
. '7 / 7
; .7 7:' : .,7 7' : 7
/7 .
pinMode(BUTTON, INPUT); // BUTTON ()
//

' 5,7.\ -'V/ ' ' ' , . '

Ardulno 63
void loop ()[
val = digitalRead(BUTTON); //
/ /
/ :
ii' //
// ,

// ,
if .( (val == HIGH) && (old_val ,==? LOW) ) {
: . .: ' -1 -' ?.C
; ,state;v= i - state; ~:-0
:'
delay (.10) ; . : !f'.
; i :z r ; 7
1 7e;|iMoe .e;7oee77e:
I * > ? '"v
old va val; /7 val. , V :
//
: V ' ;
. .if (state 1) {'".
. . ':
digitalwrite(LED, HIGH); //

64 Arduino
4
,
Arduino:
.
- ,

. ,
, , ,
, -
Arduino!

/
, .
, , ,
.

, ,
.

, ,
.

()
, .
(
).

3- Arduino 65

,
. ,
, , .


,
( ,
,
). .
. 5-1 , .
, ( ).
, , (
). , , ,
, .

. 5-1. ,

66 Arduino

( - -, . . 5-2),
, , . ,
- .
, .

, 5-2. -
( )

67

, ,
. , ,
. ,
.

.

4 -,
, , ,
, ,
, .

, ,
,
, .
, ,
. ,
. ,
,
, .

,
, ,
, . -
, , , -
. ,
,
. Arduino ,
, 4 ! ,
, - ().
, :
, ,

. . 5-3 , .

,
. ,
.

68 Arduino

(2 5 * }

(7 5 * )

. 5-3. -

, ,
, ,
.
, ,
, . ,
Arduino ,
,
.
9,10 11, an a lo g W rite ().

, ana(ogWrite(9,128) 50%-
, 9. 128? ,
a n a lo g W rite
0 255, 255 , 0
.

69

, , ,
!

. , . 5-44.
,
; () ,
() . ,
, ,
, .

70 Arduino
Arduino, 5-1 (
- www.makezine.com/
getstartedarduino).

5-1.
Apple
{define LED 9 /,/ (LED)
int i '= 0 ; //
/ /
void setup() (
pinMode(LED, OUTPUT); // Arduino,
// (LED)
)
void .loop () {
for (i = 0; i < 255; i++) { // 0 2$ 4
// *(
analogWrite (LED, i); //
delay(10); // 10 ,
// analogWrite
//
//
>
for (i - 255; i > 0; i ) ( // 255. 1
// (
ana log Write (LED, i) ; // '
delay(10); // 10
;
1

.
, Arduino
.
.

,
(. 4). ,
, . ,

71
.
- , . ,
.

, ,
. 5-4, (. 4-6). ,
,
. (.
) , ,
.
,
.

,
GND () Arduino.
Arduino GND,
, . 4-6 . 5-4,
.
GND Arduino,
, GND ,
.

, :
, . 4-6 . 4-5.
6.

, :
?

:
. ,
4-5 4 ,
. ,
,
.

72 Arduino
5-2. ,
,
, .
,
.
fdefirie LED 9 // (LED)
^define BUTTON 7 iI
ir.t val- ~ 0 ; // '
int old val - 0 ; //
.11 "val
int state = 0 ; // 0 = LED ,
// 1 = LED
int brightness =128; // -
unsigned long startTime = 0; // ?
void setup() {
pinMocie(LED, -OUTPUT); // - Arduino,
/ (LED) .
pinMode (BUTTON, INPUT);-'// BUTTON ()
//
} ....
void loop () (-
val = digitalRead (BUTTON).; //
// ,
/ ,
//
if ((val == HIGH) && (oldjval LOW) ) {
state = 1 - state; //
/
//
startTime = mili-is (); // millis () Arduino.
/ ,
//
// .
// ( ,
// )
delay (1 0 ).;.
. ,-.: .- '

73
// , .
if ((val --HIGH) && (old_val == HIGH)) {
L I]- ]; -:.
if ( s t a o e == 1 &s (m illis - o ~ a 't in ; > 5) {
'
... ' *.
_ ghcness.++; /7 -
; ] :'] y :.::. '.75:- 7;
yiyefiK delay (1 0 ); /./, .,:,
// . .
_ _ . . .; - ...'
if (brightness > 25) { .// 255 ;
brightness = 0; // 2 5 5 ,.
//
}
\
} . 5 . .r.yyi
old val = val; // val ,
//
if (state ==; 1 ) (
analogWrite(LED, brightness);,,//
// (LED)
5.7 // .
} else {

>. ' - 7 >, 4 ^Tv*',, /7.: 7 /_ 17.\o'v "-, V, _ V-v
analogWrite(LED, 0); // : (LED)

. ,
.
, .
, .
.

74 Arduino

.
- , ,
. 5-5. ( www.amperka.ru/LDR)

. 5-5.

.
, ,
. ,
, .

, 4-2 (.
4),
4-2 .

. ,
, . ,
. ,
. ,
,
. ,
.

75

, Arduino
, ,
digitalRead () .

/ ,
, ,
, .
./.,
-,
, .
, .

Arduino
Analog In ( ). ,
, ,
.
analogRead(), ,
. 0 1023,
0 5 . ,
0 2,5 , analogRead (0)
512.

, . 5-6, 10 ,
, 5-3.
(
s 13 GND,
4) ,
.

76 Arduino
77
5-3.

define LSD 13 // (LED) ,\


' ; \ -/ . ;; ; .
int val 0 ; / ,
// ,
; V -
void setup() {
pinMode (LED, OUTPUT); /
/
// .OUTPUT ()
// .
//

void 1 9 0 0 (:) i
val = analogRead(0); // .
//
digitalWrite(13, HIGH); /
d e l a y ( v a l )
//
digitalWrite(13, LOW),; //
delay(val); //
//
) < ! . ' . - ;

, 5-4.
, .
9, 5-4.
, ,
, .

78
5-4. ,
/; -'
-
#define LED 9 //, (LED)
int val - /
0 ;, ,
//,
void setup() (
pinMpcie (LED, OUTPUT); //,;
// OUTPUT ()
// .
//
1 11

void loop() (
val = analogRead(0); //
//
analogWrite(LED,; val/4); //
: - /, /, ,
.
//
delay(lO); //
//
)

, val 4, a n a lo g R e a d
0 1023, a n a lo g W r it e ()
255.

79


, ,
,
. ,

, Arduino.

, ,

. ,
, ,
.
, ,
, .


, , , Arduino
? ,
, . , ,
.
Arduino
.


, Arduino USB-,

.
,
.
Serial (
, , }.

,
.

.
( - www.makezine.
com/getstartedarduino):

80 Arduino
5~5 . -
:
fdehne STv'SCK -//
*' . . - . " '
// yyiyi.y... .
pint va.l; =: 0 ; // , /,-:
//
/ -. , '',:-.-,. ./'. !/ ;1 lid .- '''.;..;. 1 ,-
void setup/;).' {: > , p.pv
Serial.begin(9600). /
/./:.';'':
' ' ' ' 1 1 i
: //
1 i:,i ;// 9600 /
} .' 8
1
vo id Loop l
^ .'1 , , i . ^ ( . > ;,-....
...vs ,i.=. anaiogKead'iSSN. ); tu ir >m.
.
.:Seiral..piihein (val) ; //
1 , l l i i 1 -: 11 :1 ' ll: '-' ' , , -1 i l l ' , ; 'll 1
/7
idelayi'lO'O: . ) Z i 100 .; / i; :
//
I ' '. '

Arduino
Arduino Serial Monitor.
.
,
, Arduino.
,
.
Arduino Processing (www.processing.org),
.

31

(,
)
Arduino ,
20 . ,

, .
(, )
,

Arduino. --
. ,
, ,
,
.
. : ,
, -
Arduino, .

--.
, , .
, Arduino.

.

. S-7 , -
(IRF520)
. , 9--
Arduino.
-: ,
Arduino. , -
9,
analog W rite ()
- .

82 Arduino

,
, d ig ita iR e a d O
analogRead ( ) , .

.


, .
- Tutorials (www.
arduino.cc/en/Tutorial/HomePage).

83
6. ,

Arduino
,
.

Arduino.


,

,
.


,
.
.



, .


,
.


Arduino
, ,
, .

, 85
, , ,
, .
,

.

.
XXI , ,
.
, , ,
1964 .

. 6-1.

6-1, ,
,
, .
.

,
,
Make (.makezine.com) ,
peace (), love () Arduino.
, .
,
.

86 Arduino

, ,
, .
Arduino, .
Arduino USB-,

, -,
.
,
, Arduino
.

Arduino -
. ,
RSS-,
XML-, ,
Arduino. : Processing,
- XML.

Processing
Processing , Arduino.
, . Processing Ar
duino . ,
(Mac, Linux
Windows). , .
Processing ,
.

- : RSS-
- makezine.com
XML-. peace, love Arduino,
.
, Arduino.
, .
.

, ,
,
- (
) .

Arduino ,

, 87
.
HTML: (#),
.

, 8-
.
.
: , #,
(,
). ,
,
.


: Processing
Arduino. Processing,
- www.makezine.com/getstartedarduino.

6-1. Arduino;
,
.
todbot.com)
import processing.serial.*; .

String feed = "http://blog.makezine.com/index.xml";

int interval - 10; // 60 ;


int lastTime; //

int love =0;


int peace = 0;
int arduino = 0;

int light - Q> //. ,

Serial port;
color c;
String cs;

88 Arduino
String buffer = // ,

PFont font;

void-setup j
size(640,480);
frameRate(X0); .//

font = loadFont("HelveticaNeue-Bold-32.vlw");
fill (253);
textFont(font, 32);
// :
// ,
// Serial.list Arduino. ,
// ,
// , , ,
'.// . -,
// 0 [ ] ,
/ / Arduino;
//println(Serial.list );
String arduinoPort Serial.list () [0];
port = new Serial (this., arduinoPort, 9600) ;
//

- las.tTime .= 0;
fetchData ();
)
void draw(){
background( c i;
int n = (interval - ((trsillis ()-lastTime)/1 0 0 0 ));

// 3
.= color(peace, love, arduino);
cs = "#" + nex(c,6 ); //

text("Arduino Networked Lamp", 10,40);


text(" :", 10, 100);
text(feed, 10, 140);

, 89
text (" "+ + " ", 10, 450) ;
text("peace" ,1 0 ,2 0 0 );
text( " peace, 130, 200);
rect(200,172, peace, 28);

text ("love ",10,240);


text(" " + love, 130, 240);
rect;(2 0 0 ,2 1 2 , love, 28);

text{"arduino ",10/280);
text( " + arduino, 130, -280);
rect(200,252, arduino, 28);

// '
text("sending", 10, 340);
text(cs, 200,340);
text("light level, 10, 380);
rect (2 0 0 , 352, light/10.23,28) ; //.. 1023
if (n<- 0 ) (
fetchData();
lastTime = millisO;
} ;0 $ 2 ' ' -
port.write(cs)// Arduino

if (port.available(> > 0) {'ll ,


// . '' :
int inByt'e - port, read /? II
if (inByte !- 10) {; U ;
// (newline)
buffer - buffer + char(inByte) ; //
//
' }
else*

//' (newline),
//
if (buffer.length() >1) ( // ,
//

90 Arduino
// /

; / (
' ' // )
buffer = buffer.substring(0 ,buffer.length() -1 );

.//
/., . ;
1 :ght; =; iht (bu ffer i;

...p/ .: t:-v. i yoe i i


buffer ''/ /

// ,
// Ardr.i.r.o. ,
4/ ,
// ,
port.clear ;
::. ^Cr/g^ry
I 1||1|
v " ". '';;
1 i ji i u
v o id fetch D a ta O {
// .un z- l ............. l i .
//
String data; .f ' , , if
String chunk; .

7/
- love - 0 ;
peace = 0 ;
arduino' = ;-
try {
..URL .]. = new URLff eed) .; // ".
//
6RijC.6nr-oc.tioh conn -' u r l f.o p e fitq n n l i o n (/).;
co.nn,conn*5'-11 i; // /. - .

, 91
/./
// , ,
//
// , .
BufferedReader in = new BufferedReader
(new InputStreamReader(conn.getlnputStream()));
//
while ((data = in.readLine ()) != null) (

StringToker.izer st *
new StringTokenizer(data,"\"<>,. () [} ");
//
while (st.hasMoreTokens()) {
//
/ /
chunks st.nextToken().toLowerCase() ;

if (chunk.indexOf("love") >= 0 )
// "love" ()?
love++; // increment love by 1
if (chunk.'indexOf("peace") >= 0)
// "peace" ()?
peace++; // increment peace by 1
if (chunk.indexOf("arduino") >= 0)
// "arduino"?
arduino+t; // increment arduino by 1.
>

//. 64
// ,
if (peace > 64) peace = 64;
if (love > 64) love = 64;
if (arduino > 64) arduino = 64;
peace = peace * 4; // 4, ,
love = love * 4; //
//
arduino' arduino 4; // , 4

92 Arduino
catch (Exception ex) { // , ,
ex.printStackTra.ee '
System.o u t .printin("ERROR: "+ex
J. '

Processing ,
. -,
Processing ,
. ,
. , , Tools
Processing, Create Font.
HelveticaNeue-Bold, 32
.

-, ,
Arduino
. ,
Arduino.
Processing . ,
, Arduino
,
Processing
.

Arduino ( - www.
makezine.com/getstartedarduino):

, 93
6-2. Arduino
^define SENSOR
#defir.e R LED 9
Adeline G_LED 10
Adeline B~LEB 11
Adeline BUTTON 12
int val = 0; f t ,
//

int btn " LOW;


int old^btn LOW;
int state 0;
char buffer!7] ;
int. pointer *> 0;
byte inByte 0;

byte r = .0; .
byte g = 0;
byte b = 0;

void setup 0 (
Serial.begin(9600); //
.//
pinMode(BUTTON, INPUT);

void lo o p () {
val = analogRead(SENSOR); //
/ /
Serial.println(val); //
/ /

,if (Serial.available >0.) { .


// :

inByte Serial.read () ;

// , 6
if (inByte * '#' ) {
while (pointer < 6) { // 6
buffer[pointer] = Serial.read(j; ;//
pcinter++; // 1
} .i'i
// 3 ,
//
7/ 3 , g b

94 Arduino
= hex2dec(buffer[1]) + hex2dee(buffer(0]) * 16;
g hex2dec(buffer[3]) + hex2dec(buffer[2]) * 16;
b = hex2dec(buffer [5]) + hex2dec(buffer [4 ]) 16;
pointer - 0; // 0,
//
)
)
btn d.igitalRead (BUTTON) ; //.
//

// ,
if ( (btn == HIGH) && .(bld_btn == LOW) ) {
state * 1 - state;

old_btn = btn; // val ,


/ /

if (state == 1) X I I
analogWrite(R_LED, ); / /
analogWrite(G_LED, g ) ; //
analogWrite(B_LED, b ) ; //
) else (

analogWrite(R_LED, 0) I !
analogWrite(G_LED, 0)
analogWrite(B_LED, 0)

d e l a y (100); // s 100
/
)
int hex2dec(byte ) { / /
I I
if ( >= ' 1 && <= 9 * ) {
return - '01;
} else if ( >= ' ' & <= 'F') (
return - '' + 10;
)
)

, 95

. 6-2 , .
10 , , ,
.

, (
, 5).
() ,
() .
.

. 6-2. Arduino

96 Arduino
, ,
.
Arduino Processing,
, . - ,
7, .

,
.
FADO IKEA. ,
!

RGB-
( www.amperka.ru/RGB-LED),
. ,
, . 6-2, :
.
, .
Arduino 9,10 11 (
, ,
, ).


, ,
.

Arduino ,
.

RGB- ,
. ,
, , ,
, . , 4-
RGB- .

,
,
, , 5
,
.
, .

, USB-
.

4 - Arduino
, 97
Processing, .
, .

,
, .

,
, .

* -,
, - .


, .

,
.

98 Arduino
7.

Arduino
, , ,
.
,
,

.
, .
Arduino,
,
.
, , ,
, .

, Arduino
, ,
, , -
.
:

,
.
.


: divide et impera, :
.

,
.

99


, ,
.
,
.

(debugging) ,
. ,
1940- ,
- ,
.


. ,

.

,
. , .

, ,
, , ,
, ,
, .

Arduino USB- .

, (, ,
). PWR , ,
.
, , - .
USB-, USB- ,
USB- Arduino,
.
, USB-
.

Arduino
> . ,
, .

100
Arduino (Extreme, NG Diecimiia)
, ,
SV1
,
.


,
Arduino. .

,
Arduino.

Arduino , 5 .
PWR ,
. , -
. ,
, , .

, ,
, .
, Arduino ,
, .
,
Arduino USB- , ,
, USB-, .

,
.
, .

, , ,
, 5 GND
. ,
.


. -

101

. , -
( ,
), , :
... , ,
. ,
. ,
,
.

, ,
.
, , .
, -
!,
.



.
,
.
.

-,
.
.
-
, ,
.
. Practice o f Programming
,
. , ,
,
.



Arduino,
Windows.

102 Arduino
,
Arduino, ,
Arduino
run.bat.

Windows ,
Arduino 10
. Windows Arduino
. ,
, (Vista)
(Windows ) . Windows
.
Windows Vista
( ).


( LPT).
,
9 .
.
.
10 , ,
, .

Arduino, :
9 , , ,
.

,
Arduino www.
arduino.cc/en/Guide/Troubleshooting.

,
, . 8
Arduino , , ,
.


,
- . ,
Arduino ,
Google ,

103
. ,
,
. :
- .

- www.arduino.ee.
(www.arduino.cc/en/Main/
FAQ), (www.arduino.ee/
playground), ,
,
.
.

Arduino. , ,
,
,
.

,
(http://arduino.ee/forum/). ,
.
(
, ,
). ,
,
:

Arduino ?

<

Arduino?

, .
.

,
.

,
( ,
Arduino):

.
,
. - -

104 Arduino

.


, ,
? , , .
, ,
. ?
? ?
!


, Arduino. ?. , ,
- .
. , ,
, -
. .

:
. ,
, ,
, , , .

,
. ,
,
.

105
.


, , . -
- .

.
,
,
. , ,
, -, ,
, -, ,
.

,
. . -1,

, .
- ,
.
.

. -1.

. 107
(
) , ,
, .
, .
, ()
+ -,
. ,
- ,
( ,
). , ,
.
, .
-
: ,
. , ?

108 Arduino
.

,
,
. ,
,
. ,
,
, .
,
.

-
. :
, .
, ,
. ,
, ( )
. .
.


0
1
2
3
4
5

7
8
9
10%
5%

. 109
, , ,
1035%. , ? ,
, . 10 3 -
1 0, . ,
10 000 5%. ,
. 10 000
10, 10 000 000
.

,
, :
477. 4,7 , 4700 .

:

. (),
, ,
(). 100
100 .


, ,
(). 1 000 000 .
,
,
. , : 0 5
, 6 7 , 8 9
: 8, ,
, 0,01, 9,
0,1.
, 104 100 000 ,
0,1 . 229 2,2 .

110 '
.
Arduino

,
Arduino.

-: arduino.cc/en/
Reference/HomePage.

Arduino :

void setup()
,
, ,
.

void loop()
.
, ,
.

Arduino ,
, .

; ( )
( ) .
.
, .
(, .)

delay(100);

. no Arduino 111
{} ( )
. ,
, loop (),
.
:
void loop () {
Serial .prir.tln ("bye") ;

, Arduino,
( ) ,
.
Arduino:

// :
//
/* :


/*

Arduino ,
. , hi g h l o w
,
Arduino. in pu t () o u t p u t ()
.
TRUE () fa ls e () :
.

Arduino,
,
.
, .

112 Arduino
Arduino ,
.
, .

boolean ( )

: () False (),

char ( )
, . ,
Arduino , .
,
-128 127.

, : ASCII UNICODE. ASCII 127


,
, .
, ( ) -.
UNICODE ,
. ASCII -
,
, .

byte ()
0 255. ,
.

int ( )
2 -32 768
32 767. ,
Arduino.

unsigned int ( )
int, 2 ; unsigned ,
,
0 65 535.

. Arduino 113
long ( )
, int,
-2 147 483 648 2 147483 647.

unsigned long ( )
long 0 4 294 967 295.

float ( )

. 4 , ,
,
.
.

double ( )

1,7976931348623157 X 10308. !

string ()
ASCII- (

).

Null, Arduino
. :

Char stringl[] = "Arduino"; // 7 + null


Char string2[8] = "Arduino"; // To ,
//

array ()
,
. ,
. ,
,
, lightOI,
Iight02 .
, :

114 Arduino
int light[6] = (0, 20, 50, 75, 100}

array ()
: [] {}.

Arduino
.

if.-.else
. i f
, ,
. ,
, .
, , else.
if
else.

:
if (val == 1 ) [
digitalWrite (LED, HIGH) ,-
}

for
.

:
for (int i = 0; i < 10; i++) {
Serial.print("");
}

switch case
if , a switch
case .

.
, if.

. Arduino 115
:
switch (sensorValue) {
case 23:
digitalWrite(13,HIGH);
break;
case 46:
digitalWrite(12,HIGH);
break;
default: // ,
digitalWrite(12,LOW);
digitalWrite(13,LOW);
i

while
if,
.
:
// , 512
sensorValue = analogRead(1);
while (sensorValue < 512) {
digitalWrite(13,HIGH);
delay(1 0 0 );
digitalWrite(13,HIGH);
delay(1 0 0 );
sensorValue = analogRead(1);
}

do...w hile
, while, ,
.
, ,
.
:
do {
digitalWrite(13,HIGH);
delay(1 0 0 );
digitalWrite (13,HIGH);
delay(1 0 0 );
sensorValue = analogRead(I);
; while (sensorValue < 512);

116 Arduino
break ()

, .
switch case.

// , 512
go ;
// ,
if (digitaiRead(7) == HIGH)
break;
digitalWrite(13,HIGH);
delay(1 0 0 );
digitalWrite(13,HIGH) ;
delay(1 0 0 );
sensorValue = analogRead(1);
} while (sensorValue < 512);

continue ()
continue
.

:
for (light = 0; light < 255; light++)

// 140 200
if (( > 140) && ( < 200))
continue;
analogWrite(PWMpin, light);
delay (1 0 );
)

return ()
.

.

. Arduino 117
, computeremperature ()
, ,
:
i.nt computeTemperature <) {
int temperature = 0 ;
temperature = (analogRead(0) + 45) / 100;
return temperature;

Arduino ,
.
+ *,
/.

, modulo (%),
.
, ,
. , ,
(
).
:
= 2 + 2;
light = ((12 * sensorValue) - )'/ 2;
remainder = 3 % 2 ; // 2 ,
// 3 / 2

if, while
for, :
==
!=
< ,
> ,
<=
>=

118 Arduino

,
. , ,
, , 5 10,
:

if ((sensor => 5) & (sensor <= 10) }


: ,
&&; , | 1; ,
, !.



,
.
, value 1,
:
value = value +1 ;
:
value++;

( ++)
1.
. i++, i 1,
i + 1; ++i
i , 1.
.

+=, -=,*= /=
.
:

S . !
+~ 5;


Arduino
. , .

. Arduino 119
pinMode(pin, mode)

.
:
pinMode( 7 ,IN PUT); / / 7

digitalWrite(pin, mode)
.
a ig it a iW r it e ,
pinMode.
:
d ig it a lW r ic e ( 8 , HIGH); / / 8

intdigitalRead(pin)
, HIGH,
, LOW,
.
:
v a l = d ig it a lR e a d (7} ,- / /
/ / 7 v a l

int analogRead(pin)

1023, 0 5 .
:
v a l = ar.alogRead(O) ; / /
/ / 0
/ / v a l

analogWrite(pin, value)
-
PWM. pin ()
1 1 ,1 0,9 ,6 ,5 ,3 . value () 255,
0 5 .

:
a n a lo g W rite (9 ,1 2 8 ) ; / /
/ / 9 50%

120 Arduino
shiftOut(dataPin, dockPin, bitOrder, value)

,
.
. bitOrder
( ),
value .
:
shiftOut (dataPin, clockPin, LSBFIRST., 255);

pulseln(pin, value)

,
. , ,
,
.

:
time = pulseln(7,HIGH); // ,
//


Arduino ,
.

millis()
,
.
:
duration = millis()-lastTime; // ,
//

delay(Mc)

.
:
delay(500); //
//

. Arduino 121
delayMicroseconds(MKc)


.
:
delayMicroseconds(1000) ; //
// 1


Arduino
.

m in(x,y)
.
:
val = mir. (10,20); // val 10

max{x, )
.
:
val = max(10,20); // val 20

a bs(x)

,
. 5, 5,
-5, - 5.
:
val = abs(-5); // val 5

constrain^, , b)
. , ,
, , , .
:
val = constrain (ar.alogRead (0) , 0, 255);
//

122 Arduino
(, , , , )

.
.
:
val = map(analogRead(0),0,1023,100, 200);
//
// 0 1023 100 200

pow(, )
() (
).
:
double = pow(y, 32); //
// , 32-

sqrt(x)
.
:
( ) = sqrt(1138);
// 33,73425674438

5()
, .
:
sine ( ) = sin(2);
II 0,90929737091

()
, .
:
cosine ( ) = cos(2);
// -0,41614685058

. no Arduino 123
()
, .
:
tangent ( ) = (2);
II -2,18503975868


,
Arduino.

randomSeed(Ha4anbHoe )

.
, random (),
, , ,
- .
,
(, ,
, . .).
:
randomSeed(analogRead(5)); //
// , 5

random(max) randomfmin, max)




min max 1. min , 0.
:
randnum ( ) = random(0, 100);
// 0 100
randnum ( ) = random(ll);
// 0 11


5, Arduino
USB-
. .

124 Arduino
SeriaLbegrn(speed)
Arduino
.
9600 /,
, 115 200 /.
:
Serial.begin(9600);

Serial.printtaaHKbie) $!.1{, )
.
. ,
.
:
Serial.print(75); // "75"
Serial.print(75, DEC); // To , .
Serial .print (75, HEX); // "4B" (75 )
Serial.print(75, ); // "113" (75 )
Serial.print(75, BIN); // "1001011" (75 )
Serial.print(75, BYTE); // "" (
// 75
// ASCII-)

Serial. !() Serial.println(AaHHbie, )


S e r i a l . p r i n t () ,
(\\),
, Return () Enter
().
:
S e r i a l . p r i n t l r . (75) ; / / 7 5 \ r\ n "
S e r i a l . p r i n t l n (7 5 , D E C ); / / To , .
S e r i a l . p r i n t i n (7 5 , HEX); // " 4 B \ r \ n "
S e r i a l . p r i n t l n (7 5 , O CT); / / " 1 1 3 \ r\ n "
S e r i a l . p r i n t l n (7 5 , BIN); // " lO O lO lllrN n "
' S e r i a l , p r i n t l n (7-5, B Y T E ); / / " X \ r \ r."

. no Arduino 12!>
Serial.availableO
,
read .
read ,
Serial, available () 0 ,
.
:
ir.t count = Serial.available ();

Seriai.readO
.
:
int data = Serial.read ;

Serial.flush()

, , Arduino
.
, flush () .
:
Serial .flush ;

126 Arduino
.

, ,
. ,

, .


. , , ,
, .

, ,
,

- .


,
. ,

. ,
,
. :


.
,
:


,

.
:

127
, .
:

(,
).
, ,
en.wikipedia.org/wiki/Electronic_symboi.
. , -
,
().

,
:

128
Amperka.ru
,

Arduino, , ,
, ,
www.amperka.ru



. 6;
,
:429.00
',,1|| fin .: +7 (495) 788-00-75;
milLiii :
J . L li I O 1505.12 www.readgroup.ru

Вам также может понравиться