.. highlight:: csharp NeoPixel ======== NeoPixels are `Adafruit's brand `_ of LED strips that can be individually controlled. The MetaWear firmware can communicate with up to 3 strands on the WS2811 protocol with the `INeoPixel `_ interface. :: using MbientLab.MetaWear.Peripheral; INeoPixel neopixel = metawear.GetModule(); Initializing a Strand --------------------- Before we can interact with a NeoPixel strand, we first need to initialize memory on the MetaWear board to store NeoPixel information. To initialize the strand, call the `InitializeStrand `_ method. When calling the function, you will need to take into consideration these parameters: * Operating frequency (either 800 Hz or 400 Hz) * How many LEDs to use * What color ordering the strand requires (RGB, GRB, etc.) * Which gpio pin the data wire is connected to :: using MbientLab.MetaWear.Peripheral.NeoPixel; // initialize memory for a strand #2 that operates at 800KHz (fast), has 60 leds, // uses rbg color order, and has a data wire connected to gpio pin 1 IStrand strand = neopixel.InitializeStrand(2, ColorOrdering.WS2811_RBG, StrandSpeed.Fast, 1, 60); The function returns an `IStrand `_ object and can be retrieved at a later time by calling `LookupStrand `_ with the same strand number used for `InitializeStrand`. :: strand = neopixel.LookupStrand(2); Setting Colors -------------- When you have received your strand object, you can start turning on the LEDs using `SetRgb `_. Any changes to the led state will immediately be propogated to the strand unless a hold is enabled with the `Hold `_ function. When `Release `_ is called, all the LED changes will appear simultaneously. :: // Enable hold to lock the strand state strand.Hold(); strand.SetRgb(0, 255, 0, 0); strand.SetRgb(1, 0, 255, 0); strand.SetRgb(2, 0, 0, 255); // Disable hold, which will now update the strand with any state changes strand.Release(); Pattern Rotation ---------------- Once you have a color pattern on your strand, you can rotate the pattern using `Rotate `_. By default, the pattern will rotate indefinetly however you can set a limit by setting the ``repetitions`` parameter. If an indefinite rotation has started, call `StopRotation `_ to manually terminate the rotation. :: using MbientLab.MetaWear.Peripheral.NeoPixel; // Rotate pattern 16 times, moving away from the board with a delay of 500ms strand.Rotate(RotationDirection.Away, 500, repetitions: 16); // Rotate pattern indefinitely, moving towards the board with a delay of 250ms strand.Rotate(RotationDirection.Towards, 250); // Stop pattern rotation strand.StopRotation(); Clean Up -------- When you are down using your NeoPixel strand, make sure you turn off the LEDs and deallocate the memory used for that particular strand. You can discard the ``IStrand`` object after calling `Free `_. :: // turn off leds from index [0, 59] (60 leds) strand.Clear(0, 59); // free strand.Free();