コード例 #1
0
        public static void PhotoRainbowDemo(APA102LEDStrip ledStrip, int jStep, int wait, APA102LEDStrip ledStrip2 = null)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Rainbow Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            int brigthness = 6;

            var quit = false;

            ledStrip.AllOff();
            if (ledStrip2 != null)
            {
                ledStrip2.AllOff();
            }

            while (!quit)
            {
                for (var j = 0; j < 256; j += jStep)
                {
                    ConsoleEx.Gotoxy(0, 4);
                    ledStrip.Reset();
                    if (ledStrip2 != null)
                    {
                        ledStrip2.Reset();
                    }

                    for (var i = 0; i < ledStrip.MaxLed; i++)
                    {
                        ledStrip.AddRGBSequence(false, brigthness, RGBHelper.Wheel((i * 256 / ledStrip.MaxLed) + j));
                    }
                    if (ledStrip2 != null)
                    {
                        for (var i = 0; i < ledStrip2.MaxLed; i++)
                        {
                            ledStrip2.AddRGBSequence(false, brigthness, RGBHelper.Wheel((i * 256 / ledStrip.MaxLed) + j));
                        }
                    }

                    for (var i = 0; i < ledStrip.MaxLed; i++)
                    {
                        var wheelIndex = (i * 256 / ledStrip.MaxLed) + j;
                        var bkColor    = ledStrip.LedColors[i];
                        Console.WriteLine(String.Format("Color:{0}, Wheel:{1}, rgb:{2}",
                                                        bkColor.Name,
                                                        wheelIndex.ToString("000"),
                                                        APA102LEDStrip.ToDecValue(bkColor)));
                    }

                    if (ledStrip2 != null)
                    {
                        ledStrip.Show();
                        ledStrip2.ReverseSequence();
                        ledStrip2.Show().Wait(wait);
                    }
                    else
                    {
                        ledStrip.Show().Wait(wait);
                    }

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                            break;
                        }
                    }
                }
            }
            ledStrip.AllOff();
            if (ledStrip2 != null)
            {
                ledStrip2.AllOff();
            }
        }