예제 #1
0
        public static void RGBDemo(APA102LEDStrip ledStrip)
        {
            int wait        = GetWaitTimeUnit(ledStrip);
            int waitStep    = 10;
            int maxWait     = 200;
            var quit        = false;
            var userMessage = "Speed:{0}. Use Left and Right keys to change the speed";

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

            Console.Clear();
            ConsoleEx.TitleBar(0, "RGB Demo");
            ConsoleEx.WriteMenu(-1, 4, "Q)uit");
            ConsoleEx.WriteLine(0, 2, string.Format(userMessage, wait), ConsoleColor.DarkGray);

            while (!quit)
            {
                ledStrip.AddRGBSequence(true, 2, ledStrip.MaxLed - 1, Color.Blue);
                ledStrip.InsertRGBSequence(0, 14, Color.Red);
                ledStrip.ShowAndShiftRightAllSequence(wait);

                if (!Console.KeyAvailable)
                {
                    ledStrip.AddRGBSequence(true, 3, ledStrip.MaxLed - 1, Color.Green);
                    ledStrip.InsertRGBSequence(0, 16, Color.Red);
                    ledStrip.ShowAndShiftRightAllSequence(wait);
                }

                if (Console.KeyAvailable)
                {
                    while (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                        }
                        if (k == ConsoleKey.RightArrow)
                        {
                            wait += waitStep;
                            if (wait > maxWait)
                            {
                                wait = maxWait;
                            }
                        }
                        if (k == ConsoleKey.LeftArrow)
                        {
                            wait -= waitStep;
                            if (wait < 0)
                            {
                                wait = 0;
                            }
                        }
                    }
                    ConsoleEx.WriteLine(0, 2, string.Format(userMessage, wait), ConsoleColor.DarkGray);
                }
            }
            ledStrip.AllOff();
        }
예제 #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;
        }
예제 #3
0
 public static bool PlayTrigonometrieVariation(APA102LEDStrip ledStrip, int wait, List <System.Drawing.Color> colorVariations, string varName, int loopCount = 5)
 {
     Console.WriteLine("Variation:{0}", varName);
     ledStrip.Reset();
     ledStrip.AddRGBSequence(false, 6, colorVariations.ToArray());
     for (var i = 0; i < loopCount; i++)
     {
         ledStrip.ShowAndShiftRightAllSequence(wait);
         if (Console.KeyAvailable)
         {
             if (Console.ReadKey().Key == ConsoleKey.Q)
             {
                 return(false);
             }
         }
     }
     return(true);
 }