CoDrone flying outdoors

CoDrone LEDs

Now that we can fly our CoDrone, lets figure out how to program lights

The CoDrone gives you the option to change both the arm LED and eye LED colors.  To change these lights we use the CoDrone function:

You can either use the function with 3 inputs (mode, color, time) or 5 inputs (mode, Red, Green, Blue, time).

The input mode must have an input of one of these modes:

*Some of these modes may not yet be operational.  More options will be added in future CoDrone updates.

EyeNone

EyeHold

EyeMix

EyeFlicker

EyeFlickerDouble

EyeDimming

ArmNone

ArmHold

ArmMix,

ArmFlicker

ArmFlickerDouble

ArmDimming

ArmFlow

ArmFlowReverse

Eye options effect the LEDs in the eyes of the CoDrone and Arm options effect the LEDs in the arms of the CoDrone.

When using the 3 input option, the color input must be one of these colors:

*Some of these colors may not yet be operational.  More options will be added in future CoDrone updates.

AliceBlue, AntiqueWhite, Aqua,  Aquamarine, Azure, Beige,  Bisque, Black,

BlanchedAlmond,  Blue, BlueViolet, Brown,BurlyWood, CadetBlue, Chartreuse,

Chocolate, Coral, CornflowerBlue,  Cornsilk, Crimson, Cyan, DarkBlue, DarkCyan,

DarkGoldenRod,  DarkGray, DarkGreen, DarkKhaki,  DarkMagenta, DarkOliveGreen,

DarkOrange, DarkOrchid, DarkRed,DarkSalmon,  DarkSeaGreen, DarkSlateBlue,

Darkslategray, darkturquois to, darkviolet, deepp Link, deepskyblu to,dimgray,

DodgerBlue,FireBrick, FloralWhite, ForestGreen,  Fuchsia, Gainsboro, GhostWhite,

Gold, GoldenRod, Gray, Green,GreenYellow, HoneyDew,  HotPink, IndianRed, Indigo,

Ivory, Khaki, Lavender,  LavenderBlush, LawnGreen, LemonChiffon,LightBlue,

LightCoral, LightCyan, LightGoldenRodYellow, LightGray, LightGreen,  LightPink,

LightSalmon, LightSeaGreen,LightSkyBlue, LightSlateGray, LightSteelBlue, LightYellow,

Lime, LimeGreen, Linen, Magenta, Maroon, MediumAquaMarine,MediumBlue,

MediumOrchid, MediumPurple, MediumSeaGreen, MediumSlateBlue,MediumSpringGreen,

MediumTurquoise,MediumVioletRed,  MidnightBlue, MintCream,MistyRose, Moccasin,

NavajoWhite, Navy, OldLace, Olive, OliveDrab, Orange,OrangeRed,Orchid,PaleGoldenRod,

PaleGreen, PaleTurquoise, PaleVioletRed, PapayaWhip, PeachPuff,Peru, Pink, Plum,

PowderBlue, Purple, RebeccaPurple,Red, RosyBrown, RoyalBlue,SaddleBrown, Salmon,

SandyBrown, SeaGreen, SeaShell,Sienna, Silver, SkyBlue,SlateBlue, SlateGray,Snow,

SpringGreen, SteelBlue, Tan, Teal, Thistle, Tomato, Turquoise, Violet,Wheat, White,

WhiteSmoke, Yellow, YellowGreen

Here’s an example that changes the eye and arm LED colors of the CoDrone after the CoDrone pairs with the controller:

Or you can use the 5 input code to set your own combination of RBG values.  These values must be between 0 – 255:
Learn More: RGB Colors()

RGB Color Codes allow you to create thousands of unique colors with three simple inputs.

stands for red 

G stands for green 

stands for blue

Each of these values represents the amount of that specific color use in your light.  Take this code for example:

If we were to use:

our color would come out red since we are using the full value for red, and no blue or green.

If we used:

The color would be yellow because it is a mixture of red and green.

Experiment with these colors by visiting an RGB color table, such as http://www.rapidtables.com/web/color/RGB_Color.htm

Learn More 

Setting LEDs in Setup()

Here’s an example of a simple code that changes the CoDrone’s LED colors at startup:

After changing the LED colors, the new colors will remain until the CoDrone is either turned off or a new color command is sent.

An important thing to remember about using the CoDrone.LedColor() command is that it will interfere with your flight controls if looped constantly. This is because the CoDrone can only receive one command every 50ms.  If you are constantly sending the CoDrone.LedColor() command, the CoDrone will be unable to receive other commands from the controller. With this in mind, be sure to avoid writing any code that involved the CoDrone.LedColor() command constantly looping.

Bad Code
Here’s an example of a controller flight code that attempts to alternate LED colors as the CoDrone flies.  This code will not work because the controller flight commands will be “interrupted” by the LED color commands.

This code is saying:

If my timer has been less than 1000 milliseconds,
Then change my arm colors to Cyan

If my timer has been less that 2000 milliseconds,
Then change my arm colors to Green

Else reset my timer

Since the timer is always either less than 1000 or 2000, the code is constantly sending either a Green or a Cyan color command.  We need to limit the amount of color commands our code sends.

Good Code
Here is a code that achieves the same goal, but utilizes flags to limit the amount of times the CoDrone.LedColor() command is sent to the CoDrone:

 This code will only send a color command once every second.

If my timer has been more than 1000 milliseconds,
And Flag = 0
Then change my arm colors to Green and set my Flag to 1.

If my timer has been more than 1000 milliseconds,
And my Flag is not = 0
Then change my arm colors to Cyan and set my Flag to 0.

Reset my timer.

If my timer is not more than 1000 milliseconds,
Resume normal controller commands

You can see that this only sends the commands every time the timer reaches 1000 (once a second).  The timer is then reset and the flag is switched for the next color.

Try adding your own colors to this code!

Final Code

For an extra challenge, try changing the code to switch between three different colors instead of two:
Hint: Flag = 2;

Next, we’ll learn about buzzers and how to set different modes using Switch-Case statements, if-statements, and more flags.