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.

Code

int bluePin = 16; // unreverse
int redPin = 2; //reverse
int greenPin = 0; //revers

int wait = 500;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(bluePin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(bluePin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(wait); // wait for a second
digitalWrite(bluePin, LOW); // turn the LED off by making the voltage LOW
digitalWrite(redPin, LOW); // turn the LED on (HIGH is the voltage level)
delay(wait); // wait for a second
digitalWrite(redPin, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(greenPin, LOW); // turn the LED on (HIGH is the voltage level)
delay(wait); // wait for a second
digitalWrite(greenPin, HIGH); // turn the LED off by making the voltage LOW
}