User manual
28
13th Day
In the Advent calendar toda
y
•1x LED pink with dropping resisto
r
A
djustin
g
RGB via a slider in the Ap
p
In addition to displaying basic colours, an RGB-LED can also
d
isplay graduations. You can use an App to set the colour o
f
the RGB-LED precisel
y.
C
omponents: 1x board, 1xRGB-LED with dropping resistor,
1xLED pink with dropping resistor, 1xjumper
Th
e S
k
etc
h
The program
f
or this day is Tag13.in
o
and located in directory
T
ag1
3
. The RGB-LED is controlled via a string in the
f
orm RNN
-
N
GNNNBNNN. Only when a string in this
f
orm is received by
t
h
e
I
o
T-
boa
r
d
will
t
h
e
co
l
ou
r
be
set
vi
a
t
h
e
m
et
h
od
set
z
e
F
a
r
be
.
To switch o
ff
the LED, the strin
g
o
ff m
ust
be
se
n
t:
while
(
HC05.available
()
> 0
)
{
Zeichen = HC05.read
()
;
Text.concat
(
Zeichen
)
;
if
(
Zeichen == ‚\n‘
)
{
if
(
Text.indexOf
(
“R”
)
!= -1 && Text.indexOf
(
“G”
)
&& Text.indexOf
(
“B”
)
)
{
setzeFarbe
(
Text
)
;
} else if (Text.startsWith(“Off”) || Text.startsWith(“OFF”) || Text.startsWith(“off”))
{
aus
();
}
Text=
””;
}
In
t
h
e
f
u
n
ct
i
o
n setzeFarb
e
,
the submitted text is broken down into
p
arts with the substr
i
n
g
m
et
h
od
a
n
d
t
h
e
v
a
l
ues
a
r
e
t
h
e
n wri
tte
n vi
a
a
nalogWrit
e
:
void setzeFarbe
(
String text
)
{
if (text.indexOf(“R”) != -1 && text.indexOf(“G”) && text.indexOf(“B”) )
{
Strin
g
temp = text.substrin
g
(text.indexOf(“R”)+1,text.indexOf(“G”));
if
(
temp.indexOf
(
“.”
)
!= -1
)
{
temp = temp.substrin
g
(0, temp.indexOf(“.”));
}
int rot = temp.toInt
();
temp = text.substrin
g
(text.indexOf(“G”)+1,text.indexOf(“B”))
;
if
(
temp.indexOf
(
“.”
)
!= -1
)
{
temp = temp.substrin
g
(0, temp.indexOf(“.”));
}
int gruen = temp.toInt
()
;
temp = text.substrin
g
(text.indexOf(“B”)+1);
if
(
temp.indexOf
(
“.”
)
!= -1
)
{
temp = temp.substrin
g
(0, temp.indexOf(“.”));
}
int blau = temp.toInt
()
;
analo
g
Write(redPin,rot)
;
analo
g
Write(
g
reenPin,
g
ruen);
analogWrite
(
bluePin, blau
)
;
}
}
Th
e pin
k
LED is use
d
to si
g
na
l
t
h
at t
h
e connection is active.
13. Day
15007-3 Conrad Adventskalender Internet of Things 2017_en.indd 2815007-3 Conrad Adventskalender Internet of Things 2017_en.indd 28 13.08.2017 17:03:1313.08.2017 17:03:13










