Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Arduino Experiment No 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Bl

inki
nganL
ed
Obj
ect
ive
 Tobl
i
nkL
edwi
tht
hehel
pofar
duni
oboar
dandar
dui
noI
DEs
oft
war
e.

 ToL
ear
nhow t
oimpl
ementt
hedi
git
alout
put
.

 ToExpl
aint
hear
dui
noc
odef
orbl
i
nki
nganL
ed.

Equi
pme
nt
 Ar
dui
noUnoboar
dandBr
eadboar
d Ar
dui
noI
DEs
oft
war
e

 L
ED

 r
esi
stor

T
heory
Thes
pec
ifi
csket
chy
ouwantt
ous
eher
eisc
all
edBl
i
nk.I
t’
saboutt
hemos
tbas
ic
s
ket
chy
ouc
anwr
it
e,as
ortof“
Hel
l
o,wor
ld!
”forAr
dui
no.Af
ters
elec
tingar
dui
no
boar
dyouar
eus
ingands
eri
alpor
tnamedCOM 1,
COM 2,
COM 3f
rom t
het
ool
s
opt
ionont
hemenubar
.Cl
i
cki
ntheAr
dui
nowi
ndow.Fr
om t
hemenubar
,choos
e
Fi
l
e➪Exampl
es➪0Bas
ics
➪Bl
i
nk.
Afol
l
owi
ngwi
ndow i
sopeni
nfr
ontofy
ou.

1
Bef
oreupl
oadi
ngt
hes
ket
ch,Fi
rstc
li
ckt
heVer
if
ybut
ton.Ver
if
ychec
kst
hec
odet
o
makes
urei
tmakess
ens
e.Thi
sdoes
n’tnec
ess
ari
l
ymeany
ourc
odewi
l
ldowhaty
ou
ar
eant
ici
pat
ing,buti
tver
if
iest
hatt
hes
ynt
axi
swr
it
ten i
n awayAr
dui
no c
an
under
stand.
Yous
houl
dseeapr
ogr
essbarandt
het
extCompi
l
ingSket
ch(
seeFi
gur
e
bel
ow)f
oraf
ew s
econds
,fol
l
owedbyt
het
extDonec
ompi
l
ingaf
tert
hepr
oces
shas
f
ini
shed.

I
fthes
ket
chc
ompi
l
eds
ucc
ess
ful
l
y,y
ouc
annow c
li
ckt
heUpl
oadbut
tonnextt
othe
v
eri
fybut
ton.Apr
ogr
essbarappear
s,andy
ous
eeaf
lur
ryofac
tiv
ityony
ourboar
d
f
rom t
het
woL
EDsmar
kedRXandTX.Thes
eshow t
hatt
heAr
dui
noi
ssendi
ngand
r
ecei
vi
ngdat
a.Af
teraf
ew s
econds
,theRXandTXL
EDss
topbl
i
nki
ng,andaDone
Upl
oadi
ng(
see Fi
gur
e bel
ow)mes
sage appear
satt
he bot
tom oft
he Ar
dui
no
wi
ndow.
You s
houl
dseet
heL
ED mar
ked Lbl
i
nki
ng awayr
eas
sur
ingl
y:on f
ora
s
econd,of
fforas
econd.

2
Ardui
nocode

/
*Bl
i
nkTur
nsonanL
EDonf
orones
econd,t
henof
fforones
econd,r
epeat
edl
y.

Thi
sexampl
ecodei
sint
hepubl
i
cdomai
n.*/

/
/Pi
n13hasanL
EDc
onnec
tedonmos
tAr
dui
noboar
ds.

/
/gi
vei
taname:

i
ntl
ed=13;

/
/thes
etupr
out
iner
unsonc
ewheny
oupr
essr
eset
:

v
oids
etup(
){

/
/ini
ti
ali
zet
hedi
git
alpi
nasanout
put
.

pi
nMode(
led,OUTPUT)
;

3
/
/thel
oopr
out
iner
unsov
erandov
eragai
nfor
ever
:

v
oidl
oop(
){

di
git
alWr
it
e(l
ed,HI
GH)
;//t
urnt
heL
EDon(
HIGHi
sthev
olt
agel
evel
)

del
ay(
1000)
;//wai
tforas
econd

di
git
alWr
it
e(l
ed,L
OW)
;//t
urnt
heL
EDof
fbymaki
ngt
hev
olt
ageL
OW

del
ay(
1000)
;

Thes
ket
chi
smadeupofl
i
nesofc
ode.Whenl
ooki
ngatt
hec
odeasawhol
e,y
ou
c
ani
dent
if
yfourdi
sti
ncts
ect
ions
:

✓ Comment
s

✓ Dec
lar
ati
ons

✓v
oidl
oop

✓v
oids
etup

Comme
nts:

Not
icet
hatt
hec
odel
i
nesar
eenc
los
edwi
thi
nthes
ymbol
s/*and*/
.Thes
esy
mbol
s
mar
kthe begi
nni
ng and end ofa mul
ti
-l
ine orbl
ockc
omment
.Comment
sar
e
c
ompl
etel
yignor
edbyt
hes
oft
war
ewhent
hes
ket
chi
scompi
l
edandupl
oaded.
In
t
hisexampl
e,t
hec
omments
impl
ytel
l
syout
henameoft
hes
ket
ch,andwhati
t
does
,and pr
ovi
desa not
e expl
aini
ng t
hatt
hisexampl
ecode i
sint
he publ
i
c
domai
n.Thes
ymbol
s//s
igni
fyas
ingl
e-l
i
nec
ommentasoppos
ed t
o amul
ti
li
ne
c
omment
.Anyc
odewr
it
tenaf
tert
hes
eli
neswi
l
lbei
gnor
edf
ort
hatl
i
ne.I
nthi
scas
e,
t
hec
ommenti
sdes
cri
bingt
hepi
eceofc
odet
hatc
omesaf
teri
t.

4
De
clarat
ion:

Dec
lar
ati
onsar
eval
uest
hatar
est
oredf
orl
aterus
ebyt
hepr
ogr
am.I
nthi
scas
e,a
s
ingl
evar
iabl
eisbei
ngdec
lar
ed,buty
ouc
oul
ddec
lar
emanyot
herv
ari
abl
esorev
en
i
ncl
udel
i
brar
iesofc
odei
nyours
ket
ch.Fornow,al
lthati
simpor
tantt
orememberi
s
t
hatv
ari
abl
esc
anbedec
lar
edbef
oret
hes
etupf
unc
tion.

i
ntl
ed=13;

F
unct
ions:

Thenextt
wos
ect
ionsar
efunc
tionsandbegi
nwi
tht
hewor
dvoi
d:v
oids
etupand
v
oidl
oop.Af
unc
tioni
sabi
tofc
odet
hatper
for
msas
pec
ifi
ctas
k,andt
hatt
aski
s
of
tenr
epet
it
ive.Rat
hert
hanwr
it
ingt
hes
amec
odeoutagai
nandagai
n,y
ouc
an
us
eaf
unc
tiont
otel
lthec
odet
oper
for
mthi
stas
kagai
n.

Voi
dse
tup(
)

Set
up i
sthef
ir
stf
unc
tion an Ar
dui
no pr
ogr
am r
eads
,and i
trunsonl
yonc
e.I
ts
pur
pos
e,ashi
ntedi
nthename,i
stos
etupt
heAr
dui
nodev
ice,as
signi
ngv
alues
andpr
oper
ti
est
otheboar
dthatdonotc
hangedur
ingi
tsoper
ati
on.

Pi
nMode

Thepi
nModef
unc
tionc
onf
igur
esas
pec
ifi
edpi
nei
therf
ori
nputorout
put
:toei
ther
r
ecei
veors
enddat
a.Thef
unc
tioni
ncl
udest
wopar
amet
ers
:

✓ pi
n:Thenumberoft
hepi
nwhos
emodey
ouwantt
oset

✓ mode
:Ei
therI
NPUTorOUTPUT

I
ntheBl
i
nks
ket
ch,af
tert
het
wol
i
nesofc
omment
s,y
ous
eet
hisl
i
neofc
ode:

pi
nMode(
led,OUTPUT)
;

The wor
d pi
nMode i
s hi
ghl
i
ght
ed i
n or
ange.
Orange i
ndi
cat
es t
hat Ar
dui
no
r
ecogni
zest
hewor
dasac
oref
unc
tion.OUTPUTi
sal
soc
olour
edbl
ues
othati
tcan
bei
dent
if
iedasac
ons
tant
,whi
chi
sapr
edef
inedv
ari
abl
eint
heAr
dui
nol
anguage.

5
I
nthi
scas
e,t
hatc
ons
tants
etst
hemodeoft
hispi
n.

Voi
dLoop(
)

Thenexts
ect
iony
ous
eei
ntheBl
i
nks
ket
chi
sthev
oidl
oopf
unc
tion.Thi
sisal
so
hi
ghl
i
ght
edi
nor
anges
otheAr
dui
nos
oft
war
erec
ogni
zesi
tasac
oref
unc
tion.l
oop
i
saf
unc
tion,buti
nst
eadofr
unni
ngonet
ime,i
trunsc
ont
inuous
lyunt
ily
oupr
ess
t
her
esetbut
tonont
heAr
dui
noboar
dory
our
emov
ethepower
.

Di
git
alwri
te

Wi
thi
nthel
oopf
unc
tion,y
ouagai
nseec
url
ybr
acket
sandt
wodi
ff
erentor
ange
f
unc
tions
:di
git
alWr
it
eanddel
ay.
Fir
sti
sdi
git
alWr
it
e:

di
git
alWr
it
e(l
ed,HI
GH)
;//s
ett
heL
EDon

Thec
omments
ayss
etL
ED on,butwhatexac
tlydoest
hatmean?Thef
unc
tion
di
git
alWr
it
esendsadi
git
alv
aluet
oapi
n.di
git
alpi
nshav
eonl
ytwos
tat
es:onorof
f.
I
nel
ect
ri
calt
erms
,thes
ecanber
efer
redt
oasei
theraHI
GHorL
OW v
alue,whi
chi
s
r
elat
ivet
othev
olt
ageoft
heboar
d.AnAr
dui
noUnor
equi
res5Vt
orun,whi
chi
s
pr
ovi
dedbyei
theraUSBorahi
gherext
ernalpowers
uppl
y,whi
cht
heAr
dui
no
boar
dreduc
est
o5V.Thi
smeanst
hataHI
GHv
aluei
sequalt
o5VandL
OW i
sequal
t
o0V.
Thef
unc
tioni
ncl
udest
wopar
amet
ers
:

✓ pi
n:Thenumberoft
hepi
nwhos
emodey
ouwantt
oset

✓ val
ue:Ei
therHI
GHorL
OW

Sodi
git
alWr
it
e(l
ed,HI
GH)
;inpl
ainEngl
i
shwoul
dbe“
send5Vt
opi
n

13ont
heAr
dui
no,
”whi
chi
senoughv
olt
aget
otur
nonanL
ED.

di
git
alWr
it
e(l
ed,L
OW)
;//s
ett
heL
EDof
f

Thi
stel
l
sAr
dui
not
osend0V(
ground)t
opi
n13,whi
cht
urnst
heL
EDof
f.

6
De
lay

Thi
sfunc
tiondoesj
ustwhati
tsay
s:I
tst
opst
hepr
ogr
am f
oranamountoft
imei
n
mi
l
li
sec
onds
.Int
hisc
ase,t
hev
aluei
s1000 mi
l
li
sec
onds
,whi
chi
sequalt
o one
s
econd.Dur
ingt
hist
ime,not
hinghappens
.

Ci
rcui
tDi
agram:

Proce
dure
:

 L
edi
sconnec
tedt
opi
n13onmos
tar
dui
noboar
ds,s
oify
ou'
reus
ingt
hepi
n
13 y
ou don'
trequi
reL
ed,r
esi
storand br
eadboar
d.Ot
her
wis
e,Fol
l
ow t
he
c
irc
uitdi
agr
am andc
onnec
tthec
omponent
sas

 Connec
toneendofL
edt
oout
putpi
n(exc
eptpi
n13)t
hroughar
esi
stor
andot
herendt
ogr
oundpi
nonar
dui
noboar
d.

 Pl
uggedy
ourAr
dui
noi
ntoy
ourc
omput
er

 Opent
heAr
dui
nos
oft
war
e

 Sett
heboar
dands
eri
alpor
t

 Opent
heBl
i
nks
ket
chf
rom t
heExampl
esf
olderandupl
oadi
ttot
heboar
d

7
As
signment

Cr
eat
eapr
ogr
am t
hatwi
l
lbl
i
nkt
woL
EDs
;oner
ed,onegr
een,al
ter
nat
ely
.Thati
s,
whent
her
edL
EDc
omeson,t
hegr
eens
houl
dtur
nof
fandwhent
hegr
eenc
omes
on,t
her
eds
houl
dtur
nof
f.Ther
eds
houl
dbeonf
ort
wos
econdsandt
hegr
een
s
houl
dbeonf
orones
econd.Atnot
imes
houl
dbot
hLEDsbeons
imul
taneous
lyor
of
fsi
mul
taneous
ly(
atl
eas
tnotwi
thi
nor
dinar
yhumanper
cept
ion)
.Thi
sbl
i
nki
ng
pat
ter
nshoul
drepeatov
erandov
er:r
edonf
ort
wos
econds
,gr
eenonf
orone
s
econd,r
edonf
ort
wo,gr
eenonf
orone,ands
oon.

I
ncl
udey
ourc
odeandapr
opers
chemat
icdi
agr
am wi
thc
omponentv
alues
.Iti
s
s
ugges
tedt
hatMul
ti
si
m oranot
hers
chemat
icc
apt
urepr
ogr
am beus
edt
ogener
ate
t
hes
chemat
ic.

You might also like