Beruflich Dokumente
Kultur Dokumente
3
Circuit 2
PIN 11
RGB LED
PIN 10 RedBoard You know what’s even more fun than a blinking
LED? Changing colors with one LED. RGB, or
PIN 9 red-green-blue, LEDs have three different color-emit-
ting diodes that can be combined to create all sorts of
Resistors (330 ohm) colors. In this circuit, you’ll learn how to use an RGB
(Orange-Orange-Brown) LED to create unique color combinations.
Depending on how bright each diode is, nearly any
color is possible!
LED
BLUE
GREEN
RED
(Light-Emitting Diode)
GND
(Ground)
LED
IC
Potentiometer
330Ω Transistor
LED Wire
330Ω
PARTS:
F
SE
3.
T
3V
5V
GN
RE
D
PO
GN
SE
D
W
VI
T
ER
N
A0
A1
A2
AN
SC A
RX
L
A3
E
AL
SD EF
L
TX
A
A4
AR ND
R
O
13
N
G
A5
.
IN
G 13
S
H
A
R
E
.
12
H
~
A
11
C
~
K
10
.
~
IS
9
D 7
P
8
IG T ~
AL ~5
(P 4
6
O
W
N
M ~
~ 2
)
3
TX
RX
1
0
red
blue
common
green
p.10
Page 29
Circuit 3: RGB LED
Page 30
a b c d e f g h i
1 1
2 2
3 3
4 4
5 5
RESET
6 6
* The longest lead is the common(gnd). 7 7
8 8
7-15V
9 9
10 10
SCL
11 11
SDA
12 12
AREF 13 13
GND 14 14
13 15 15
IOREF
13
TX
RX
12 16 16
RESET
~11 17 17
3.3V
~10 18 18
5V
~9 19 19
GND
8 20 20
GND
POWER
VIN 7 21 21
~6 22 22
A0 ~5 23 23
A1 4 24 24
DIGITAL (PWM~)
A3 2 26 26
A4 TX 1 27 27
ON
ANALOG IN
A5 RX 0 28 28
ISP
29 29
30 30
a b c d e f g h i
Component: Image Reference: The shocking truth behind analogWrite():
a4 a5 a6 a7
RGB LED (5mm) We've seen that the Arduino can read analog voltages (voltages between 0 and
5 volts) using the analogRead() function. Is there a way for the RedBoard to
output analog voltages as well?
330Ω Resistor 5V e7
e4 e1
g41
The answer is no... and yes. The RedBoard does not have a true analog voltage
output. But, because the RedBoard is so fast, it can fake it using something
330Ω Resistor 5V e6
e7 e1
g61
called PWM ("Pulse-Width Modulation"). The pins on the RedBoard with
“~” next to them are PWM/Analog out compatible.
330Ω Resistor 5V e7 e1
g71
The RedBoard is so fast that it can blink a pin on and off almost 1000 times
per second. PWM goes one step further by varying the amount of time that
Jumper Wire Pin 9 h4 the blinking pin spends HIGH vs. the time it spends LOW. If it spends most
of its time HIGH, a LED connected to that pin will appear bright. If it
spends most of its time LOW, the LED will look dim. Because the pin is
Jumper Wire e5
blinking much faster than your eye can detect, the RedBoard creates the
illusion of a "true" analog output.
Jumper Wire Pin 10 h6
HIGH (5 volts)
Jumper Wire Pin 11 h7 90% 0.5V
LOW (0 volts)
10%
Jumper Wire 5V +
HIGH (5 volts)
Jumper Wire GND 50%
LOW (0 volts)
2.5V
50%
10%
HIGH (5 volts)
LOW (0 volts)
4.5V
90%
Page 31
3
Circuit 2 Arduino Code:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 3
Code to Note:
A for() loop is used to step a number across a range, and repeatedly runs
for (x = 0; x < 768; x++) code within the brackets {}. Here the variable "x" starts a 0, ends at 767,
{} and increases by one each time ("x++").
if (x <= 255) "If / else" statements are used to make choices in your programs. The statement
{} within the parenthesis () is evaluated; if it's true, the code within the first brackets {}
else will run. If it's not true, the code within the second brackets {} will run.
{}
F
3.
3
5V D O W
GN D E R
RE
P
GN
SE
VI
T
N
A0
A1
A2
AN
SC A
RX X
LE
A3
T TX
AL
AR
SD EF
L
A4
R1X3
AR ND
O
N
G
A5
.S
13
IN
G 13
H
AR
E.
12
H
~ 0
AC
11
~ 9
K.
1
~
IS
D 7
P
IG
8
IT ~
AL ~5
(P 4
6
O
W
N
M ~
~ 2
)
TX
3
RX
1
0
analogWrite(RED_PIN, redIntensity);
to
analogWrite(RED_PIN, redIntensity/3);
Page 32