Esempio n. 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();
        }
Esempio n. 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(Environment.NewLine, ",").Split(',').ToList();
            
            while (!quit)
            {
                foreach (var sBColor in bkColors) 
                {
                    if(string.IsNullOrEmpty(sBColor.Trim()))
                        continue;

                    var bkColor = APA102LEDStrip.DrawingColors[sBColor];

                    bkColor = APA102LEDStrip.ToBrighter(bkColor, -65);

                    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, 20);

                    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;
        }