Overview

In this lesson, you will learn how to use a RGB (Red Green Blue) LED with an Espcopter.

At first glance, RGB (Red, Green, Blue) LEDs look just like regular LEDs, however, inside the usual LED package, there are actually three LEDs, one red, one green and yes, one blue. By controlling the brightness of each of the individual LEDs you can mix pretty much any color you want.
You will use the analogWrite function of Arduino to control the color of the LED.

 

/*
ESP8266 RGB Led
*/

void setup() {
pinMode(2, OUTPUT); // Initialize the LED_BUILTIN pin as an output
pinMode(10, OUTPUT); // Initialize the LED_BUILTIN pin as an output
pinMode(16, OUTPUT); // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {

digitalWrite(2, LOW);
digitalWrite(10, LOW);
digitalWrite(16, LOW);
delay(1000);
digitalWrite(2, HIGH);
digitalWrite(10, HIGH);
digitalWrite(16, LOW);
delay(1000);
digitalWrite(2, HIGH);
digitalWrite(10, LOW);
digitalWrite(16, HIGH);
delay(1000); // Wait for one seconds (to demonstrate the active low LED)
}