Beispiel #1
0
 public void SetLed(Led led, Color color)
 {
     try
     {
         _ledStrip.SetLEDColor(Channel, (int)led, color);
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Leds exception: {ex}");
     }
 }
Beispiel #2
0
        protected override void ProcessRecord()
        {
            if (NumberOfCycles == 0)
            {
                NumberOfCycles = 1;
            }

            Settings settings = Settings.CreateDefaultSettings();

            settings.Channel = new Channel(NumberOfLeds, GpioPin, Brightness, Invert, StripType.WS2812_STRIP);
            WS281x       controller = new WS281x(settings);
            List <Color> colors     = GetColors();

            for (int iterations = 0; iterations < NumberOfCycles; ++iterations)
            {
                for (int colorCycle = 0; colorCycle < colors.Count; ++colorCycle)
                {
                    Color currentColor = colors[colorCycle];
                    for (int i = 0; i < NumberOfLeds; ++i)
                    {
                        //Iterate over all LEDs and display the current color
                        controller.SetLEDColor(i, currentColor);
                        controller.Render();
                        Thread.Sleep(25);
                    }
                }
            }
        }
Beispiel #3
0
        protected override void ProcessRecord()
        {
            Settings settings = Settings.CreateDefaultSettings();
            //settings.Channels[0] = new Channel(30, GpioPin, _brightness, Invert, StripType.WS2812_STRIP);
            bool breathingAsc = true;
            int  i            = 0;

            while (true)
            {
                settings.Channel = new Channel(30, GpioPin, (byte)_brightness, Invert, StripType.WS2812_STRIP);
                using (WS281x controller = new WS281x(settings))
                {
                    //controller.SetLEDColor(this.LedId, this.Color);
                    controller.SetLEDColor(0, Color.Green);
                    controller.SetLEDColor(1, Color.Yellow);
                    controller.SetLEDColor(2, Color.Red);
                    controller.Render();
                }
                //Console.WriteLine($"Hello - {i}");
                //Console.WriteLine($"Current brightness - {_brightness}");

                if (_brightness >= 255)
                {
                    _brightness  = 255;
                    breathingAsc = false;
                }
                else if (_brightness <= 0)
                {
                    breathingAsc = true;
                    _brightness  = 0;
                }

                if (breathingAsc)
                {
                    _brightness += 1;
                }
                else
                {
                    _brightness -= 1;
                }
                i += 1;
                Console.WriteLine($"index = {i} / Brightness = {_brightness} / BreathingAsc = {breathingAsc}");
                //Thread.Sleep(50);
            }
        }
Beispiel #4
0
        protected override void ProcessRecord()
        {
            if (ExplosionColor == Color.Empty)
            {
                ExplosionColor = Color.OrangeRed;
            }
            if (string.IsNullOrEmpty(Speed))
            {
                Speed = "Medium";
            }

            Settings settings = Settings.CreateDefaultSettings();

            settings.Channel = new Channel(NumberOfLeds, GpioPin, Brightness, Invert, StripType.WS2812_STRIP);
            WS281x controller = new WS281x(settings);

            int leftSideIterations = NumberOfLeds / 2;

            // If it's even, both sides will have the same amount of iterations, otherwise make right side have one more
            int rightSideIterations = (NumberOfLeds % 2 == 0) ? leftSideIterations : leftSideIterations + 1;
            int totalIterations = 0, leftSide = 0, rightSide = NumberOfLeds - 1;

            for (; totalIterations < rightSideIterations; ++totalIterations)
            {
                controller.SetLEDColor(leftSide++, LeftSideColor);
                controller.SetLEDColor(rightSide--, RightSideColor);
                controller.Render();
                Thread.Sleep(_speedTranslation[Speed]);
            }

            for (; totalIterations >= 0; --totalIterations)
            {
                controller.SetLEDColor(leftSide--, ExplosionColor);
                controller.SetLEDColor(rightSide++, ExplosionColor);
                controller.Render();
                Thread.Sleep(10);
            }

            //Thread.Sleep(_speedTranslation[Speed]);

            //controller.SetColorOnAllLEDs(ExplosionColor);
            //controller.Render();
            //for some reason it has to be explicitly disposed
            controller.Dispose();
        }
Beispiel #5
0
 private static void Wipe(WS281x controller, Color color)
 {
     for (int i = 0; i <= controller.GetController().LEDCount - 1; i++)
     {
         controller.SetLEDColor(0, i, color);
         controller.Render();
         System.Threading.Thread.Sleep(1000 / 15);
     }
 }
 protected static void Wipe(WS281x controller, Color color)
 {
     for (int i = 0; i <= controller.Settings.Channels[0].LEDs.Count - 1; i++)
     {
         controller.SetLEDColor(0, i, color);
         controller.Render();
         System.Threading.Thread.Sleep(1000 / 15);
     }
 }
Beispiel #7
0
        public void Render(IEnumerable <Pixel> pixelsToRender)
        {
            foreach (var p in pixelsToRender)
            {
                _ws281x.SetLEDColor(0, p.PixelID, p.PixelColor);
            }

            _ws281x.Render();
        }
Beispiel #8
0
        protected override void ProcessRecord()
        {
            Settings settings = Settings.CreateDefaultSettings();

            settings.Channel = new Channel(NumberOfLeds, GpioPin, Brightness, Invert, StripType.WS2812_STRIP);
            WS281x controller = new WS281x(settings);


            for (int i = 0; i < NumberOfLeds; ++i)
            {
                for (int j = 0; j < i; ++j)
                {
                    controller.SetLEDColor(j, Color.Empty);
                }
                controller.SetLEDColor(i, Color);
                controller.Render();
                Thread.Sleep(_speedTranslation[Speed]);
            }
            //"hack". turn the last led off
            controller.SetLEDColor(NumberOfLeds - 1, Color.Empty);
            controller.Render();
            //for some reason it has to be explicitly disposed
            controller.Dispose();
        }
        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.Channel_1 = new Channel(ledCount, 18, 255, false, StripType.WS2812_STRIP);

            using (var controller = new WS281x(settings))
            {
                var colors = GetAnimationColors();
                while (!request.IsAbortRequested)
                {
                    for (int i = 0; i <= controller.Settings.Channel_1.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);
                }
            }
        }
 protected override void ProcessRecord()
 {
     controller.SetLEDColor(this.LedId, this.Color);
     controller.Render();
 }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var settings = Settings.CreateDefaultSettings();

            //Use 16 LEDs and GPIO Pin 18.
            //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(12, 18, 255, false, StripType.WS2812_STRIP);

            using (var rpi = new WS281x(settings))
            {
                while (true)
                {
                    // draw an X
                    rpi.SetLEDColor(0, 0, Color.Red);
                    rpi.SetLEDColor(0, 2, Color.Red);
                    rpi.SetLEDColor(0, 4, Color.Red);
                    rpi.SetLEDColor(0, 6, Color.Red);
                    rpi.SetLEDColor(0, 8, Color.Red);
                    rpi.Render();
                    Thread.Sleep(3000);
                    // clean
                    rpi.SetLEDColor(0, 0, Color.Black);
                    rpi.SetLEDColor(0, 2, Color.Black);
                    rpi.SetLEDColor(0, 4, Color.Black);
                    rpi.SetLEDColor(0, 6, Color.Black);
                    rpi.SetLEDColor(0, 8, Color.Black);
                    rpi.Render();

                    for (int i = 0; i < 10; i++)
                    {
                        rpi.SetLEDColor(0, 2, Color.Black);
                        rpi.SetLEDColor(0, 6, Color.Black);
                        rpi.SetLEDColor(0, 1, Color.Blue);
                        rpi.SetLEDColor(0, 4, Color.Blue);
                        rpi.SetLEDColor(0, 7, Color.Blue);
                        rpi.Render();
                        Thread.Sleep(150);

                        rpi.SetLEDColor(0, 1, Color.Black);
                        rpi.SetLEDColor(0, 7, Color.Black);
                        rpi.SetLEDColor(0, 0, Color.Blue);
                        rpi.SetLEDColor(0, 8, Color.Blue);
                        rpi.Render();
                        Thread.Sleep(150);

                        rpi.SetLEDColor(0, 0, Color.Black);
                        rpi.SetLEDColor(0, 8, Color.Black);
                        rpi.SetLEDColor(0, 3, Color.Blue);
                        rpi.SetLEDColor(0, 5, Color.Blue);
                        rpi.Render();
                        Thread.Sleep(150);

                        rpi.SetLEDColor(0, 3, Color.Black);
                        rpi.SetLEDColor(0, 5, Color.Black);
                        rpi.SetLEDColor(0, 2, Color.Blue);
                        rpi.SetLEDColor(0, 6, Color.Blue);
                        rpi.Render();
                        Thread.Sleep(150);
                    }

                    // clean
                    rpi.SetLEDColor(0, 2, Color.Black);
                    rpi.SetLEDColor(0, 4, Color.Black);
                    rpi.SetLEDColor(0, 6, Color.Black);
                    rpi.Render();

                    // draw checked
                    rpi.SetLEDColor(0, 1, Color.Green);
                    rpi.SetLEDColor(0, 3, Color.Green);
                    rpi.SetLEDColor(0, 7, Color.Green);
                    rpi.SetLEDColor(0, 11, Color.Green);
                    rpi.Render();
                    Thread.Sleep(3000);

                    // clean
                    rpi.SetLEDColor(0, 1, Color.Black);
                    rpi.SetLEDColor(0, 3, Color.Black);
                    rpi.SetLEDColor(0, 7, Color.Black);
                    rpi.SetLEDColor(0, 11, Color.Black);
                    rpi.Render();
                }
            }
        }
Beispiel #12
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;
                    }
                }
            }
        }