2.6: LEDs

Make sure that your drone is paired with Blockly before starting the lesson! If you are unsure of how to pair, go back to the Pairing to Blockly lesson to review!LED stands for “light-emitting diode”. A diode is an electronic device that allows an electronic current to flow in only one direction. LEDs are beginning to replace traditional light bulbs because they are more efficient. 

Your CoDrone EDU has 2 RGB LEDs: one in the center of the drone and one in the remote controller. RGB stands for red, green, and blue. Using the three colors, you can create almost every color imaginable! Aside from making your drone look cool, LEDs provide another form of feedback. For example, the drone light can tell you the connection status of your drone. A solid light means your drone is connected, while a flashing light indicates theres a disconnection.CoDrone EDU provides functionality so that you can change the CoDrone EDU’s LED or the remote controller’s LED! All of these functions can be found in the Lights menu. 

Each LED block has the same three components:

Red, green, blue – An LED produces a color as a combination of red, green, and blue (hence the name RGB LED). All of these values range from 0 to 255 corresponding to the color’s intensity, with 255 being the highest. For example, the RGB values for the color red correspond to [255,0,0]. What are the RGB values for blue and green? What about purple? Use an RGB color picker like this one to find out!

Brightness – Determines the brightness of the LED. This can be any number from 0 to 100.Practice using the LEDs to make a rainbow. You will need to research which RGB color value will make each color of the rainbow. For example, how you make orange from red, green, and blue light? Try this code to see what color you see.

Build a rainbow that cycles through red, orange, yellow, green, blue, purple on the drone. Add a sleep(1) in between each color to see it for 1 second. Set the last parameter to 255 for the highest brightness.Challenge: Fading LEDs

An LED fading in and out can be done by increasing and then decreasing the brightness. In the loops category,use the count block to easily loop through values of 0 to 255.

The variable “i” can be used to replace the brightness parameter inside of the block. The variable “i” is automatically generated when you use the count block.Hints:

  • Counting by 1 may be too slow. Try increasing the last parameter.
  • To count down from 255, one of your parameters has to be a negative number.
In this lesson, you learned about the CoDrone EDU’s LEDs. You learned how to change the color of the LED using RGB values, and how to combine LEDs with other blocks to make a fading LED.