Note: this page refers to a product that is retired.

EsploraBlink

Blink the RGB LED on the Esplora.

This sketch blinks the Esplora's RGB LED. It goes through all three primary colors (red, green, blue), then it combines them for secondary colors(yellow, cyan, magenta), then it turns on all the colors to create white.

For best results, cover the LED with a piece of white paper to see the colors blend.

Hardware Required

  • Arduino Esplora

Circuit

Only your Arduino Esplora is needed for this example. Connect the Esplora to your computer with a USB cable.

RGB led on the Esplora
RGB led on the Esplora

Code

The RGB LED is comprised of three colors that represent the three primary colors: red, green, and blue.

To control all the colors with one instruction you use the writeRGB() function. It take three arguments. Each value represents the brightness of the red, green, and blue element, respectively. The brightness scales between 0 (for completely off) to 255 (for completely on).

After setting the brightness of an LED, use delay() to pause the sketch for a second, so the light stays in the state you left it.

It's also possible to control each light individually with the following functions :

1/*
2
3 Esplora Blink
4
5 This sketch blinks the Esplora's RGB LED. It goes through
6
7 all three primary colors (red, green, blue), then it
8
9 combines them for secondary colors(yellow, cyan, magenta), then
10
11 it turns on all the colors for white.
12
13 For best results cover the LED with a piece of white paper to see the colors.
14
15 Created on 22 Dec 2012
16
17 by Tom Igoe
18
19 This example is in the public domain.
20
21 */
22
23#include <Esplora.h>
24
25void setup() {
26
27 // There's nothing to set up for this sketch
28}
29
30void loop() {
31
32 Esplora.writeRGB(255, 0, 0); // make the LED red
33
34 delay(1000); // wait 1 second
35
36 Esplora.writeRGB(0, 255, 0); // make the LED green
37
38 delay(1000); // wait 1 second
39
40 Esplora.writeRGB(0, 0, 255); // make the LED blue
41
42 delay(1000); // wait 1 second
43
44 Esplora.writeRGB(255, 255, 0); // make the LED yellow
45
46 delay(1000); // wait 1 second
47
48 Esplora.writeRGB(0, 255, 255); // make the LED cyan
49
50 delay(1000); // wait 1 second
51
52 Esplora.writeRGB(255, 0, 255); // make the LED magenta
53
54 delay(1000); // wait 1 second
55
56 Esplora.writeRGB(255, 255, 255); // make the LED white
57
58 delay(1000); // wait 1 second
59
60}

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.