public static void Main()
        {
            // Create three colors, all LEDs off
            RGB first = new RGB(0, 0, 0);
            RGB second = new RGB(0, 0, 0);
            RGB third = new RGB(0, 0, 0);

            // Put them into an array
            RGB[] colors = { first, second, third };

            // Use D6 for CIN and D7 for DIN (Grove Base Shield v1.2 header #6)
            OutputPort cin = new OutputPort(Pins.GPIO_PIN_D6, false);
            OutputPort din = new OutputPort(Pins.GPIO_PIN_D7, false);

            // Create our chainable RGB led object using the ports from above
            ChainableRGBLed leds = new ChainableRGBLed(cin, din);

            // Loop forever
            while (true)
            {
                // Set the colors
                leds.setColors(colors);

                // Randomize each color
                randomize(first);
                randomize(second);
                randomize(third);
            }
        }
        private static void randomize(RGB color)
        {
            do
            {
                // Increment the counter to get the next number and keep it within the bounds of the table
                counter++;
                counter = counter % increments.Length;

                // XOR a new prime with the red value
                color.red = (byte) (color.red ^ increments[counter]);

                // Increment the counter to get the next number and keep it within the bounds of the table
                counter++;
                counter = counter % increments.Length;

                // XOR a new prime with the green value
                color.green = (byte) (color.green ^ increments[counter]);

                // Increment the counter to get the next number and keep it within the bounds of the table
                counter++;
                counter = counter % increments.Length;

                // XOR a new prime with the blue value
                color.blue = (byte) (color.blue ^ increments[counter]);
            } while ((color.red == 0) && (color.green == 0) && (color.blue == 0));
            // Repeat this loop if all of the colors end up being zero (avoids a strobing effect)
        }
        public void setColors(RGB[] colors)
        {
            bool first = true;
            bool last = false;

            // Loop through each color
            foreach(RGB rgb in colors) {
                // Set it
                setColor(rgb, first, last);

                // Make sure first is no longer true
                first = false;
            }

            // We're done, send the end frame
            sendEndFrame();
        }
 private void setColor(RGB rgb, bool first, bool last)
 {
     setColor(rgb.red, rgb.green, rgb.blue, first, last);
 }
        public static void Main()
        {
            // Create three colors, all LEDs off
            RGB first = new RGB(0, 0, 0);
            RGB second = new RGB(0, 0, 0);
            RGB third = new RGB(0, 0, 0);

            int counter = 0;
            int whichLed;

            // Put them into an array
            RGB[] colors = { first, second, third };

            // Use D6 for CIN and D7 for DIN (Grove Base Shield v1.2 header #6)
            OutputPort cin = new OutputPort(Pins.GPIO_PIN_D6, false);
            OutputPort din = new OutputPort(Pins.GPIO_PIN_D7, false);

            // Create our chainable RGB led object using the ports from above
            ChainableRGBLed leds = new ChainableRGBLed(cin, din);

            // Loop forever
            while (true)
            {
                // Set the colors
                leds.setColors(colors);

                // Increment the counter
                counter += 8;

                // Determine which LED we're cycling
                whichLed = counter >> 8;

                if (whichLed == 0)
                {
                    // Make the first LED red and turn off the second and third
                    first.red = (byte) (counter & 0xFF);
                    second.green = 0;
                    third.blue = 0;
                }
                else if (whichLed == 1)
                {
                    // Make the second LED green and turn off the first and third
                    first.red = 0;
                    second.green = (byte) (counter & 0xFF);
                    third.blue = 0;
                }
                else if (whichLed == 2)
                {
                    // Make the third LED blue and turn off the first and second
                    first.red = 0;
                    second.green = 0;
                    third.blue = (byte) (counter & 0xFF);
                }

                // Make sure the counter rolls properly after it runs through all three LEDs (256 * 3)
                if (counter >= 768)
                {
                    // We've looped through all three LEDs, start over
                    counter = 0;
                }
            }
        }