public void Execute(AbortRequest request)
        {
            Console.Clear();
            Console.Write("How many LEDs to you want to use: ");

            var ledCount = Int32.Parse(Console.ReadLine());

            //The default settings uses a frequency of 800000 Hz and the DMA channel 10.
            var settings = Settings.CreateDefaultSettings();

            //Use Unknown as strip type. Then the type will be set in the native assembly.
            var controller = settings.AddController(ControllerType.PWM0, ledCount, StripType.WS2812_STRIP);

            using (var device = new WS281x(settings))
            {
                var colors = GetAnimationColors();
                while (!request.IsAbortRequested)
                {
                    for (int i = 0; i < controller.LEDCount; i++)
                    {
                        var colorIndex = (i + colorOffset) % colors.Count;
                        controller.SetLED(i, colors[colorIndex]);
                    }

                    device.Render();

                    if (colorOffset == int.MaxValue)
                    {
                        colorOffset = 0;
                    }
                    colorOffset++;
                    System.Threading.Thread.Sleep(50);
                }
            }
        }
        public override void Execute(AbortRequest request)
        {
            using (var controller = GetController())
            {
                var colors = GetAnimationColors();
                while (!request.IsAbortRequested)
                {
                    for (int i = 0; i <= controller.Settings.Channels[0].LEDCount - 1; i++)
                    {
                        var colorIndex = (i + colorOffset) % colors.Count;
                        controller.SetLEDColor(0, i, colors[colorIndex]);
                    }

                    controller.Render();

                    if (colorOffset == int.MaxValue)
                    {
                        colorOffset = 0;
                    }
                    colorOffset++;
                    System.Threading.Thread.Sleep(50);
                }

                Wipe(controller, Color.Empty);
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var abort = new AbortRequest();

            Console.CancelKeyPress += (s, e) =>
            {
                e.Cancel = true;
                abort.IsAbortRequested = true;
            };

            var input = 0;

            do
            {
                Console.Clear();
                Console.WriteLine("What do you want to test:");
                Console.WriteLine("Press CTRL + C to abort to current test.");
                Console.WriteLine("0 - Exit");
                Console.WriteLine("1 - Color wipe animation");
                Console.WriteLine("2 - Rainbow color animation");

                Console.Write("What is your choice: ");
                input = Int32.Parse(Console.ReadLine());

                var animation = GetAnimation(input);
                if (animation != null)
                {
                    abort.IsAbortRequested = false;
                    animation.Execute(abort);
                }
            } while (input != 0);
        }
Ejemplo n.º 4
0
        public void Execute(AbortRequest request)
        {
            Console.Clear();
            Console.Write("How many LEDs to you want to use: ");

            var ledCount = Int32.Parse(Console.ReadLine());

            //The default settings uses a frequency of 800000 Hz and the DMA channel 10.
            var settings = Settings.CreateDefaultSettings();

            //Set brightness to maximum (255)
            //Use Unknown as strip type. Then the type will be set in the native assembly.
            settings.Channels[0] = new Channel(ledCount, 18, 10, false, StripType.WS2812_STRIP);


            using (var controller = new WS281x(settings))
            {
                while (!request.IsAbortRequested)
                {
                    Wipe(controller, Color.Red);
                    Wipe(controller, Color.Green);
                    Wipe(controller, Color.Blue);
                    Wipe(controller, Color.Yellow);
                    Wipe(controller, Color.FromArgb(255, 255, 255));
                }
            }
        }
Ejemplo n.º 5
0
        public override void Execute(AbortRequest request)
        {
            using (var controller = GetController())
            {
                while (!request.IsAbortRequested)
                {
                    Wipe(controller, Color.Red);
                    Wipe(controller, Color.Green);
                    Wipe(controller, Color.Blue);
                }

                Wipe(controller, Color.Empty);
            }
        }
 public abstract void Execute(AbortRequest request);
Ejemplo n.º 7
0
        public void Execute(AbortRequest request)
        {
            Console.Clear();
            Console.Write("How many LEDs to you want to use: ");

            var ledCount = Int32.Parse(Console.ReadLine());

            //The default settings uses a frequency of 800000 Hz and the DMA channel 10.
            var settings = Settings.CreateDefaultSettings();

            //Set brightness to maximum (255)
            //Use Unknown as strip type. Then the type will be set in the native assembly.
            settings.Channels[0] = new Channel(ledCount, 18, 255, false, StripType.WS2812_STRIP);

            var controller = new WS281x(settings);

            //int ledIndex = 0;
            //int rad = 0;
            //int green = 0;
            //int blue = 0;
            while (!request.IsAbortRequested)
            {
                //Console.Write("rad,green,blue");//"ledIndex,rad,green,blue");
                //string input = Console.ReadLine();
                //string[] split = input.Split(',');

                ////ledIndex = Convert.ToInt16(split[0]);
                //rad = Convert.ToInt16(split[0]);
                //green = Convert.ToInt16(split[1]);
                //blue = Convert.ToInt16(split[2]);

                int  maxBrigtness = 100;
                bool flg          = false;
                for (int blue = 0; blue < maxBrigtness; blue++)
                {
                    for (int green = 0; green < maxBrigtness; green++)
                    {
                        for (int rad = 0; rad < maxBrigtness; rad++)
                        {
                            for (int i = 0; i < ledCount; i++)
                            {
                                controller.SetLEDColor(0, i, Color.FromArgb(rad, green, blue));
                            }
                            controller.Render();
                            //System.Threading.Thread.Sleep(10);
                            if (!request.IsAbortRequested)
                            {
                                break;
                            }
                        }

                        for (int rad = maxBrigtness; rad > 0; rad--)
                        {
                            for (int i = 0; i < ledCount; i++)
                            {
                                controller.SetLEDColor(0, i, Color.FromArgb(rad, green, blue));
                            }
                            controller.Render();
                            //System.Threading.Thread.Sleep(10);
                            if (!request.IsAbortRequested)
                            {
                                break;
                            }
                        }

                        if (flg)
                        {
                            break;
                        }
                    }

                    for (int green = maxBrigtness; green > 0; green--)
                    {
                        for (int i = 0; i < ledCount; i++)
                        {
                            controller.SetLEDColor(0, i, Color.FromArgb(0, green, blue));
                        }
                        controller.Render();
                        //System.Threading.Thread.Sleep(10);
                        if (!request.IsAbortRequested)
                        {
                            break;
                        }
                    }
                    if (flg)
                    {
                        break;
                    }
                }
            }
        }