Exemple #1
0
        /// <summary>
        /// Test a strip on 1 APA 102 RGB LED.
        /// Old Nusbio extension use nusbio pin 4 for the clock and pin 5 for the data.
        /// APA 102 use a compatible SPI protocol with no CS and MISO, just CLOCK and MOSI.
        /// </summary>
        /// <param name="spi"></param>
        static void Api102RgbLedSample(ISPI spi)
        {
            var brightness = APA102LEDStrip.MAX_BRIGHTNESS / 3 * 2;
            var wait       = 100;
            var api102     = new APA102LEDStrip(1, spi);
            var done       = false;

            while (!done)
            {
                for (int i = 0; i <= 255; i += 4)
                {
                    if (System.Console.KeyAvailable)
                    {
                        if (System.Console.ReadKey().Key == ConsoleKey.Q)
                        {
                            done = true;
                            break;
                        }
                    }

                    var color = APA102LEDStrip.Wheel(i);
                    System.Console.WriteLine($"Index:{i:000}, Color:{APA102LEDStrip.ToHexValue(color)}");
                    api102
                    .AllToOneColor(color, brightness)
                    .Show()
                    .Wait(wait);
                }
            }
            api102.AllOff();
        }
Exemple #2
0
        public static void ScrollDemo(APA102LEDStrip ledStrip)
        {
            var wait = GetWaitTimeUnit(ledStrip);
            var quit = false;

            ledStrip.Brightness = 16;

            ledStrip.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Scroll Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            var bkColors = TargetColors.Replace("\r", "").Replace("\n", ",").Split(',').ToList();

            while (!quit)
            {
                foreach (var sBColor in bkColors)
                {
                    if (string.IsNullOrEmpty(sBColor.Trim()))
                    {
                        continue;
                    }

                    var bkColor = APA102LEDStrip.DrawingColors[sBColor];

                    Console.WriteLine(String.Format("Background Color:{0}, Html:{1}, Dec:{2}",
                                                    bkColor.Name.PadRight(16),
                                                    APA102LEDStrip.ToHexValue(bkColor),
                                                    APA102LEDStrip.ToDecValue(bkColor)));

                    var fgColor = APA102LEDStrip.ToBrighter(bkColor, -10);

                    ledStrip.AddRGBSequence(true, 4, ledStrip.MaxLed - 1, bkColor);
                    ledStrip.InsertRGBSequence(0, 15, fgColor);
                    ledStrip.ShowAndShiftRightAllSequence(wait);

                    if (Console.KeyAvailable)
                    {
                        quit = true;
                        break;
                    }
                }
            }
            ledStrip.AllOff();
            var k = Console.ReadKey(true).Key;
        }
Exemple #3
0
        public static void LineDemo(APA102LEDStrip ledStrip)
        {
            int wait = ledStrip.MaxLed <= 10 ? 55 : 0;
            var quit = false;

            ledStrip.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Line Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            while (!quit)
            {
                var j = 0;

                for (var i = 0; i < ledStrip.MaxLed; i++)
                {
                    // Remark: there should be a faster way to draw the line, by first setting all the led
                    // to black and only resetting the one in color. Once we light up all the led, we would
                    // turn them all off and re start... Todo, totry.
                    var bkColor = RGBHelper.Wheel(((i * 256 / ledStrip.MaxLed) + j));
                    ledStrip.AddRGBSequence(true, 2, i + 1, bkColor);
                    if (++j >= 256)
                    {
                        j = 0;
                    }
                    while (!ledStrip.IsFull)
                    {
                        ledStrip.AddRGBSequence(false, 2, Color.Black);
                    }

                    ledStrip.Show().Wait(wait);

                    Console.WriteLine(String.Format("Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)));

                    if (Console.KeyAvailable)
                    {
                        while (Console.KeyAvailable)
                        {
                            var k = Console.ReadKey(true).Key;
                            if (k == ConsoleKey.Q)
                            {
                                quit = true;
                                break;
                            }
                        }
                    }
                }
                ledStrip.Wait(wait * 3).AllOff();
            }
            ledStrip.AllOff();
        }
Exemple #4
0
        public static void MultiShades(APA102LEDStrip ledStrip)
        {
            int wait = 0;
            var quit = false;

            ledStrip.AllOff();

            while (!quit)
            {
                for (var j = 0; j < 256; j++)
                {
                    Console.Clear();
                    ledStrip.Reset();

                    for (var i = 0; i < ledStrip.MaxLed; i++)
                    {
                        ledStrip.AddRGBSequence(false, 10, RGBHelper.Wheel(((i + j))));
                    }

                    foreach (var bkColor in ledStrip.LedColors)
                    {
                        Console.WriteLine(String.Format("Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)));
                    }

                    ledStrip.Show().Wait(wait);

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                            break;
                        }
                    }
                }
            }
            ledStrip.AllOff();
        }
Exemple #5
0
        public static void AlternateLineDemo(APA102LEDStrip ledStrip)
        {
            var wait = GetWaitTimeUnit(ledStrip);

            if (ledStrip.MaxLed <= 10)
            {
                wait *= 3;
            }

            var quit = false;

            ledStrip.Brightness = 16;
            ledStrip.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Alternate Line Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            var bkColors = TargetColors.Replace(Environment.NewLine, ",").Split(',').ToList();

            while (!quit)
            {
                foreach (var sBColor in bkColors)
                {
                    if (string.IsNullOrEmpty(sBColor.Trim()))
                    {
                        continue;
                    }

                    var bkColor = APA102LEDStrip.ToBrighter(APA102LEDStrip.DrawingColors[sBColor], -75);

                    Console.WriteLine(String.Format("Background Color:{0}, Html:{1}, Dec:{2}",
                                                    bkColor.Name.PadRight(16),
                                                    APA102LEDStrip.ToHexValue(bkColor),
                                                    APA102LEDStrip.ToDecValue(bkColor)));

                    var fgColor = APA102LEDStrip.ToBrighter(bkColor, 40);

                    ledStrip.Reset();
                    for (var l = 0; l < ledStrip.MaxLed; l += 2)
                    {
                        ledStrip.AddRGBSequence(false, 4, bkColor);
                        ledStrip.AddRGBSequence(false, 6, fgColor);
                    }

                    for (var i = 0; i < ledStrip.MaxLed * 3; i += 4)
                    {
                        ledStrip.Show().ShiftRightSequence().Wait(wait);
                        if (Console.KeyAvailable)
                        {
                            break;
                        }
                    }

                    if (Console.KeyAvailable)
                    {
                        quit = true;
                        break;
                    }
                }
            }
            ledStrip.AllOff();
            var k = Console.ReadKey(true).Key;
        }
Exemple #6
0
        public static void LineDemo(APA102LEDStrip ledStripe)
        {
            int wait = 20;
            var quit = false;

            ledStripe.AllOff();
            Console.Clear();
            ConsoleEx.WriteMenu(-1, 4, "Q)uit");

            while (!quit)
            {
                var j = 0;

                for (var i = 0; i < ledStripe.MaxLed; i++)
                {
                    var bkColor = RGBHelper.Wheel(((i * 256 / ledStripe.MaxLed) + j));
                    ledStripe.AddRGBSequence(true, 2, i + 1, bkColor);
                    if (++j >= 256)
                    {
                        j = 0;
                    }
                    while (!ledStripe.IsFull)
                    {
                        ledStripe.AddRGBSequence(false, 2, Color.Black);
                    }

                    ledStripe.Show().Wait(wait);

                    Console.WriteLine(String.Format("Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)));

                    if (Console.KeyAvailable)
                    {
                        while (Console.KeyAvailable)
                        {
                            var k = Console.ReadKey(true).Key;
                            if (k == ConsoleKey.Q)
                            {
                                quit = true;
                                break;
                            }
                        }
                    }
                }
                ledStripe.Wait(wait * 3).AllOff();
            }
            ledStripe.AllOff();
        }
Exemple #7
0
        public static void RainbowDemo(APA102LEDStrip ledStrip0, int jStep, APA102LEDStrip ledStrip1, bool inSync)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Rainbow Demo", ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 6, "Q)uit");

            int wait       = 13;
            var quit       = false;
            var maxStep    = 256;
            var brightness = 16;

            ledStrip0.AllOff();
            ledStrip1.AllOff();

            while (!quit)
            {
                var j2 = maxStep;
                for (var j = 0; j < maxStep; j += jStep)
                {
                    if (inSync) // If in sync both led show the same color else show opposite color
                    {
                        j2 = j;
                    }

                    ledStrip0.Reset();
                    ledStrip1.Reset();

                    for (var i = 0; i < ledStrip0.MaxLed; i++)
                    {
                        ledStrip0.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j)));
                    }

                    for (var i = 0; i < ledStrip1.MaxLed; i++)
                    {
                        ledStrip1.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j2)));
                    }

                    foreach (var bkColor in ledStrip0.LedColors)
                    {
                        ConsoleEx.WriteLine(1, 2, String.Format("Strip 0 - Color:{0}, Html:{1}, Dec:{2}, WheelIndex:{3}      ", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor), j), ConsoleColor.DarkCyan);
                    }
                    foreach (var bkColor in ledStrip1.LedColors)
                    {
                        ConsoleEx.WriteLine(1, 3, String.Format("Strip 1 - Color:{0}, Html:{1}, Dec:{2}, WheelIndex:{3}", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor), j2), ConsoleColor.DarkCyan);
                    }

                    ledStrip0.Show();
                    ledStrip1.Show().Wait(wait);

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                            break;
                        }
                    }
                    j2--;
                }
            }
            ledStrip0.AllOff();
            ledStrip1.AllOff();
        }
Exemple #8
0
        public static void ComboWith6LedPanel(Nusbio nusbio, APA102LEDStrip ledStrip0, APA102LEDStrip ledStrip1 = null)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Rainbow Demo", ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 6, "Q)uit");

            int wait       = 50;
            var quit       = false;
            var maxStep    = 256;
            var brightness = 5;
            int jStep      = 8;

            ledStrip0.AllOff();
            ledStrip1.AllOff();

            var ledIndex        = -1;
            var maxLedIndex     = 4;
            var ledIndexTimeOut = new TimeOut(wait * 50);

            while (!quit)
            {
                var j2 = maxStep;
                for (var j = 0; j < maxStep; j += jStep)
                {
                    ledStrip0.Reset();
                    ledStrip1.Reset();

                    for (var i = 0; i < ledStrip0.MaxLed; i++)
                    {
                        ledStrip0.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j)));
                    }

                    for (var i = 0; i < ledStrip1.MaxLed; i++)
                    {
                        ledStrip1.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j2)));
                    }

                    foreach (var bkColor in ledStrip0.LedColors)
                    {
                        ConsoleEx.WriteLine(1, 2, String.Format("Strip 0 - Color:{0}, Html:{1}, Dec:{2}", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)), ConsoleColor.DarkCyan);
                    }
                    foreach (var bkColor in ledStrip1.LedColors)
                    {
                        ConsoleEx.WriteLine(1, 3, String.Format("Strip 1 - Color:{0}, Html:{1}, Dec:{2}", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)), ConsoleColor.DarkCyan);
                    }
                    j2 -= jStep;
                    if (j2 < 0)
                    {
                        j2 = maxStep;
                    }

                    ledStrip0.Show();
                    ledStrip1.Show().Wait(wait);

                    /*
                     * // Turn on and off led connected to gpio 0,1,2,3
                     * if (ledIndexTimeOut.IsTimeOut())
                     * {
                     *  if (ledIndex != -1)
                     *      nusbio[ledIndex].Low();
                     *  ledIndex++;
                     *  if (ledIndex == maxLedIndex)
                     *      ledIndex = 0;
                     *  nusbio[ledIndex].High();
                     * }
                     */

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                            break;
                        }
                    }
                }
            }
            ledStrip0.AllOff();
            ledStrip1.AllOff();
        }
Exemple #9
0
        public static void ColorsSequence(APA102LEDStrip ledStripe0, APA102LEDStrip ledStripe1)
        {
            var wait = 300;
            var quit = false;

            ledStripe0.Brightness = 7;
            ledStripe0.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Color Sequence Demo", ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 4, "Q)uit");

            var bkColors = TargetColors.Replace(Environment.NewLine, ",").Split(',').ToList();

            while (!quit)
            {
                foreach (var sBColor in bkColors)
                {
                    if (string.IsNullOrEmpty(sBColor.Trim()))
                    {
                        continue;
                    }

                    var bkColor = APA102LEDStrip.DrawingColors[sBColor];
                    ConsoleEx.Gotoxy(1, 2);
                    ConsoleEx.WriteLine(string.Format("Background Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)), ConsoleColor.DarkCyan);

                    ledStripe0.Reset().AddRGBSequence(true, ledStripe0.Brightness, ledStripe0.MaxLed, bkColor).Show();
                    ledStripe1.Reset().AddRGBSequence(true, ledStripe1.Brightness, ledStripe0.MaxLed, bkColor).Show().Wait(wait);

                    if (Console.KeyAvailable)
                    {
                        quit = true;
                        break;
                    }
                }
            }
            ledStripe0.AllOff();
            var k = Console.ReadKey(true).Key;
        }