EsploraBlink
Blink the RGB LED on the Esplora.
Esplora Blink
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.
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 Blink4
5 This sketch blinks the Esplora's RGB LED. It goes through6
7 all three primary colors (red, green, blue), then it8
9 combines them for secondary colors(yellow, cyan, magenta), then10
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 201216
17 by Tom Igoe18
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 sketch28}29
30void loop() {31
32 Esplora.writeRGB(255, 0, 0); // make the LED red33
34 delay(1000); // wait 1 second35
36 Esplora.writeRGB(0, 255, 0); // make the LED green37
38 delay(1000); // wait 1 second39
40 Esplora.writeRGB(0, 0, 255); // make the LED blue41
42 delay(1000); // wait 1 second43
44 Esplora.writeRGB(255, 255, 0); // make the LED yellow45
46 delay(1000); // wait 1 second47
48 Esplora.writeRGB(0, 255, 255); // make the LED cyan49
50 delay(1000); // wait 1 second51
52 Esplora.writeRGB(255, 0, 255); // make the LED magenta53
54 delay(1000); // wait 1 second55
56 Esplora.writeRGB(255, 255, 255); // make the LED white57
58 delay(1000); // wait 1 second59
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.