User manual

11
4t
h
Da
y
In the Advent calendar today
•1x LED yellow with dropping resisto
r
Alternating
ash
Two LEDs
ash alternatin
g
l
y.
C
omponents: 1x board, 1xLED yellow with dropping resi
-
stor, 1xLED red with dropping resisto
r
The pro
g
ra
m
The program
f
or this day is called
T
ag04.
i
no an
d
l
ocate
d
in
d
irectory
T
ag0
4
.
const
i
nt ledP
i
n1 = 10;
const
i
nt ledP
i
n2 = 12;
i
nt ledState = LOW
;
i
nt p
i
n = ledP
i
n1
;
v
oid setup
()
{
pinMode(ledPin1
,
OUTPUT)
;
pinMode
(
ledPin2, OUTPUT
);
digitalWrite
(
ledPin1, LOW
);
digitalWrite(ledPin2, LOW)
;
}
v
oid loop() {
if
(
pin == ledPin1
)
{
p
i
n = ledP
i
n2
;
digitalWrite(ledPin1, LOW)
;
}
e
l
se
{
p
i
n = ledP
i
n1
;
di
g
italWrite
(
ledPin2, LOW
);
}
di
g
italWrite(pin, HIGH);
delay(500)
;
}
How t
h
e pro
g
ram wor
ks
if (
p
in == ledPin1) {
p
i
n = ledP
i
n2
;
di
g
italWrite(ledPin1, LOW)
;
} else {
p
i
n = ledP
i
n1
;
di
g
italWrite(ledPin2, LOW)
;
}
T
h
e temporary varia
bl
e p
i
n saves w
h
ic
h
LED is current
l
y
l
it. Initia
ll
y t
h
is va
l
ue is ledP
i
n
1
. An i
f
-query
switches the variable to the other pin, and the currently lit LED is switched o
ff
. Switching takes place
every 5
00
ms
.
Both cathodes
(
short legs of the LED
)
must be connected to GND. The left one is the yellow LED,
t
h
e rig
h
t one t
h
e re
d
LED
.
4. Day
15007-3 Conrad Adventskalender Internet of Things 2017_en.indd 1115007-3 Conrad Adventskalender Internet of Things 2017_en.indd 11 13.08.2017 17:03:0213.08.2017 17:03:02