using MbientLab.MetaWear.Peripheral; INeoPixel neopixel = metawear.GetModule<INeoPixel>();
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);
strand = neopixel.LookupStrand(2);
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();
Once you have a color pattern on your strand, you can rotate the pattern using
By default, the pattern will rotate indefinetly however you can set a limit by setting the
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();