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

Pushbut

ton
Obj
ect
ive

 Tol
ear
nhow t
oimpl
ementt
hedi
git
ali
nputordi
git
alr
eadf
unc
tionofan
ar
dui
nobyi
nter
fac
ingpus
hbut
tonwi
thar
dui
no.

Equi
pme
nt

 Ar
dui
noUNOboar
d

 Ar
dui
noI
DESof
twar
e

 Pus
hbut
ton

 Res
ist
or

 Wi
res

T
heory

Thi
sexer
cis
eexami
nesbas
icdi
git
ali
nputc
odeandhar
dwar
efort
hemi
croc
ont
rol
l
er.
Ty
pic
all
y,t
hec
ont
rol
l
erwi
l
lneedt
oreac
ttoext
ernalt
rue/
fal
ses
tat
echangesf
rom
ei
theraus
erors
omeot
herc
irc
uit
.Forexampl
e,aus
ermaypus
habut
toni
ndi
cat
ing
t
hatt
heywantt
ost
artors
topapr
oces
ssuc
hasmut
inganaudi
osi
gnalorengagi
ng
anel
ect
ri
cmot
or.Ther
eisno“
hal
fway
”wi
tht
hes
esor
tsoft
hings
;youdon’
t“
sor
tof
s
tar
tamot
oral
i
ttl
ebi
t”
,youei
therdoi
tordon’
t.Thec
ont
rol
l
er’
sdi
git
ali
nputpi
ns
ar
edes
ignedf
orpr
eci
sel
ythi
ssor
tofs
ignal
.Inputs
ignal
smus
tconf
ormt
opr
oper
l
ogi
clev
elsi
nor
dert
opr
oper
lyt
ri
ggert
hec
ont
rol
l
er.I
nthec
aseoft
heAr
dui
noUno
t
hatmeanst
hes
ignal
smus
tadher
etot
hes
tandar
d0Vand5V.Thes
ignals
our
ces
c
anbet
houghtofi
nter
msoft
wobr
oadc
ategor
ies
:ac
tiv
eandpas
siv
e.Anac
tiv
e
s
our
cewoul
dbeac
irc
uits
uchasal
ogi
cgat
eorc
ompar
atort
hatdr
ivest
hei
nput
pi
nto5V or0V.Fors
omeappl
i
cat
ionst
hisi
sexc
ess
iveandwec
angetbywi
th
s
omet
hingmuc
hsi
mpl
er,namel
ythepas
siv
ety
pe.Fort
hes
e,ani
nter
nalpul
l
-up
r
esi
stori
senabl
edont
hei
nputpi
noft
hec
ont
rol
l
er.Thepul
l
-upi
sal
argev
alue
r
esi
stort
iedbet
weent
hepowers
uppl
yandt
hei
nputpi
n.Thepul
l
-upwi
l
lcr
eat
ea

1
l
ogi
chi
ghatt
hei
nput(
i.
e.,t
hei
nputpi
nis“
pul
l
edhi
gh”
).Toac
hiev
eal
ow,we
c
onnec
tas
impl
eswi
tchf
rom t
hepi
nto gr
ound.No ot
herext
ernalc
irc
uit
ryor
poweri
sneeded.Obv
ious
ly,a pul
l
-up s
houl
d be di
sabl
ed when us
ing ac
tiv
e
s
our
ces
.To r
ead t
hel
ogi
clev
elatan i
nput
,two t
hingsmus
tbedone.Fi
rst
,the
c
orr
espondi
ngdat
adi
rec
tionr
egi
sterbi
tmus
tbes
etf
ori
nputorr
eadmode(
and
opt
ional
l
y,wemayal
sowi
sht
oengaget
hepul
l
-up)
.Onc
ethi
sisdonewet
henr
ead
t
heappr
opr
iat
epor
tpi
nbi
t.I
tiswor
thnot
ingt
hatons
omemi
croc
ont
rol
l
erst
he
s
amer
egi
steri
sus
edf
orbot
hinputandout
put(
e.g.
,thePORTBr
egi
sterasus
edon
t
hedi
git
alwr
it
eexer
cis
e).Ont
heAt
melAVRs
eri
es(
suc
hast
heATmega328Pus
ed
ont
heUno)
,howev
er,t
wodi
ff
erentaddr
ess
esar
eus
ed:PORTxf
orwr
it
ingandPI
Nx
f
orr
eadi
ng.A c
ommoner
rorf
ort
henew AVRpr
ogr
ammeri
stot
ryt
oreadf
rom
PORTBwhent
heyr
eal
l
ywantt
oreadf
rom PI
NB.I
nthi
sexampl
ewe’
l
ltoggl
ean
i
nputpi
n wi
th as
impl
eSPSTs
wit
ch us
ing an i
nter
nalpul
l
-up.Thes
tat
ewi
l
lbe
obs
erv
edus
ingt
heSer
ialMoni
tor
.

Ci
rcui
tDi
agram:

(
wit
hExt
ernalpul
l
-upr
esi
stor
) (
wit
hint
ernalpul
l
-upr
esi
stor
)

2
Proce
dure

 Fol
l
ow t
heCi
rcui
tDi
agr
am wi
thi
nter
nalpul
l
-up r
esi
storand Connec
tthe
Component
sas Sol
derac
oupl
ewi
rest
oanSPSTs
wit
chandc
onnec
tthem
t
opi
n8andgr
ound.I
fyoupr
efer
,youc
ans
impl
yins
ertawi
rei
ntoAr
dui
no
pi
n8andt
henmanual
l
yins
ertt
hef
reeendi
ntooneoft
hegr
oundc
ont
act
s
whenneeded. OR Connec
ttheComponent
sac
cor
dingt
otheCi
rcui
t
Di
agr
am wi
thExt
ernalpul
lupr
esi
stor
.

 Pl
uggedy
ourAr
dui
noi
ntoy
ourc
omput
er.

 Opent
heAr
dui
nos
oft
war
e.

 Sett
heboar
dands
eri
alpor
t.

 Ty
pet
hec
odei
ntot
heedi
tor
,compi
l
eitandupl
oadt
otheboar
d.

 Opent
hes
eri
almoni
torandobs
erv
edt
hes
tat
esofi
nputpi
n.Changi
ngt
he
pos
iti
onofs
wit
chy
ou'
lls
eet
hes
eri
esofonesandz
eros
.

Ardui
noCode

/
*ReadDi
git
alI
nputV1.Moni
tor
sAr
dui
nopi
n8ands
endsv
aluet
othe

Ser
ialMoni
tor*/

v
oids
etup(
)

Ser
ial
.begi
n(9600)
;

pi
nMode(
8,I
NPUT_PUL
LUP)
;

v
oidl
oop(
)

3
i
nti
;

i=di
git
alRead(
8);

Ser
ial
.pr
int
ln(
i)
;

Expl
anat
ion:

Fi
rstweopent
hes
eri
almoni
torandt
hens
ett
hedat
adi
rec
tionr
egi
sterf
ori
nput
modewi
th pul
l
-up v
iat
hepi
nMode(
)func
tion (
set
ti
ng t
hemodet
ojus
tINPUT
di
sabl
est
hepul
lup)
.Int
hel
oopi
ngs
ect
ionwer
eadt
hev
aluef
rom pi
n8andt
hen
r
epor
titbac
ktot
heSer
ialMoni
tor
.Compi
l
ethec
odeandt
rans
feri
ttot
heAr
dui
no
boar
d.Opent
heSer
ialMoni
tor
.Yous
houl
dseeas
eri
esofl
ogi
chi
ghs(
1)s
crol
l
ing
by
.Now i
nser
tthef
reeendoft
hewi
rei
ntooneoft
hegr
oundheader
s.TheSer
ial
Moni
tors
houl
dnow s
how as
eri
esofl
ogi
clows(
0)s
crol
l
ingby
.Asy
ouc
onnec
tand
di
sconnec
tthewi
re(
ort
hrow t
hes
wit
ch)t
hev
aluess
houl
dfl
i
pbac
kandf
ort
h.

Assi
gnme
nt

A pus
h-but
ton mi
ghtbe us
ed t
otoggl
e a dev
ice.Forexampl
e,pus
htot
urn
s
omet
hingon,pus
hagai
ntot
urni
tof
f.Modi
fyt
heexi
sti
ngc
odes
othatt
hes
wit
ch
t
oggl
est
hes
tat
eoft
heL
EDLConnec
tedt
opi
n13.Thati
s,t
heL
EDs
houl
dchange
s
tat
eonl
yonal
ow-
to-
hight
rans
iti
onoft
hes
wit
ch(
oral
ter
nat
ely
,onl
yonahi
gh-
to-
l
ow t
rans
iti
on)
.Inc
ludey
ourc
odeandt
heac
company
ings
chemat
icdi
agr
am dr
awn
us
ingMul
ti
si
m oranot
hers
chemat
icc
apt
uret
ool
.

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