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

/*
 RGB
 ESPcopter
 By Metehan Emlik
 */

int bluePin = 10;
 int redPin = 16;
 int greenPin = 2; // This pin is workink reverse because of circuit design..!!

// the setup function runs once when you press reset or power the board
 void setup() {
 // initialize digital pin 13 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)
 digitalWrite(greenPin, HIGH); // turn the LED on (HIGH is the voltage level)
 digitalWrite(redPin, LOW); // turn the LED on (HIGH is the voltage level)
 delay(1000); // wait for a second
 digitalWrite(bluePin, LOW); // turn the LED on (HIGH is the voltage level)
 digitalWrite(greenPin, LOW); // turn the LED on (HIGH is the voltage level)
 digitalWrite(redPin, LOW); // turn the LED on (HIGH is the voltage level)
 delay(1000); // wait for a second
 digitalWrite(bluePin, LOW); // turn the LED on (HIGH is the voltage level)
 digitalWrite(greenPin, HIGH); // turn the LED on (HIGH is the voltage level)
 digitalWrite(redPin, HIGH); // turn the LED on (HIGH is the voltage level)
 delay(1000); // wait for a second
 }