Beispiel #1
0
        public static void TrigonometrieOneColorDemo(APA102LEDStrip ledStrip)
        {
            var wait = GetWaitTimeUnit(ledStrip);

            if (ledStrip.MaxLed <= 10)
            {
                wait *= 3;
            }

            var maxLed = ledStrip.MaxLed;
            var quit   = false;

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

            Console.Clear();
            ConsoleEx.TitleBar(0, "Trigonometrie Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            var _4Sin_div_PI   = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(radianV) / (1 * Math.PI), colorMinValue: 64);
            var _4Sin3_div_3PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(3 * radianV) / (3 * Math.PI), colorMinValue: 64);
            var _4Sin5_div_5PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(5 * radianV) / (5 * Math.PI), colorMinValue: 32);
            var _4Sin7_div_7PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(7 * radianV) / (7 * Math.PI), colorMinValue: 32);

            // Green
            var greenColorVariation0 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin_div_PI, null);
            var greenColorVariation1 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin3_div_3PI, null);
            var greenColorVariation2 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin5_div_5PI, null);
            var greenColorVariation3 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin7_div_7PI, null);

            while (!quit)
            {
                if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation0, "4*Math.Sin(radianV)  /(1*Math.PI)"))
                {
                    break;
                }
                if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation1, "4*Math.Sin(3*radianV)/(3*Math.PI)"))
                {
                    break;
                }
                if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation2, "4*Math.Sin(5*radianV)/(5*Math.PI)"))
                {
                    break;
                }
                if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation3, "4*Math.Sin(7*radianV)/(7*Math.PI)"))
                {
                    break;
                }

                if (Console.KeyAvailable)
                {
                    if (Console.ReadKey().Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }
            }
            ledStrip.AllOff();
        }
Beispiel #2
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();
        }
Beispiel #3
0
        /// <summary>
        /// Test a strip on 1 APA 102 RGB LED.
        /// Old Nusbio extension use nusbio pin 4 for the clock and pin 5 for the data.
        /// APA 102 use a compatible SPI protocol with no CS and MISO, just CLOCK and MOSI.
        /// </summary>
        /// <param name="spi"></param>
        static void Api102RgbLedSample(ISPI spi)
        {
            var brightness = APA102LEDStrip.MAX_BRIGHTNESS / 3 * 2;
            var wait       = 100;
            var api102     = new APA102LEDStrip(1, spi);
            var done       = false;

            while (!done)
            {
                for (int i = 0; i <= 255; i += 4)
                {
                    if (System.Console.KeyAvailable)
                    {
                        if (System.Console.ReadKey().Key == ConsoleKey.Q)
                        {
                            done = true;
                            break;
                        }
                    }

                    var color = APA102LEDStrip.Wheel(i);
                    System.Console.WriteLine($"Index:{i:000}, Color:{APA102LEDStrip.ToHexValue(color)}");
                    api102
                    .AllToOneColor(color, brightness)
                    .Show()
                    .Wait(wait);
                }
            }
            api102.AllOff();
        }
Beispiel #4
0
        public static void LineDemo(APA102LEDStrip ledStrip)
        {
            int wait = ledStrip.MaxLed <= 10 ? 55 : 0;
            var quit = false;

            ledStrip.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Line Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            while (!quit)
            {
                var j = 0;

                for (var i = 0; i < ledStrip.MaxLed; i++)
                {
                    // Remark: there should be a faster way to draw the line, by first setting all the led
                    // to black and only resetting the one in color. Once we light up all the led, we would
                    // turn them all off and re start... Todo, totry.
                    var bkColor = RGBHelper.Wheel(((i * 256 / ledStrip.MaxLed) + j));
                    ledStrip.AddRGBSequence(true, 2, i + 1, bkColor);
                    if (++j >= 256)
                    {
                        j = 0;
                    }
                    while (!ledStrip.IsFull)
                    {
                        ledStrip.AddRGBSequence(false, 2, Color.Black);
                    }

                    ledStrip.Show().Wait(wait);

                    Console.WriteLine(String.Format("Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)));

                    if (Console.KeyAvailable)
                    {
                        while (Console.KeyAvailable)
                        {
                            var k = Console.ReadKey(true).Key;
                            if (k == ConsoleKey.Q)
                            {
                                quit = true;
                                break;
                            }
                        }
                    }
                }
                ledStrip.Wait(wait * 3).AllOff();
            }
            ledStrip.AllOff();
        }
Beispiel #5
0
        public static void PerformanceTest(APA102LEDStrip ledStrip)
        {
            ledStrip.Brightness = 16;
            ledStrip.AllOff();
            Console.Clear();
            Console.WriteLine("Running test...");

            var bkColor    = Color.Red;
            var sw         = Stopwatch.StartNew();
            var testCount  = 1000;
            var wheelIndex = 0;

            // This loop set the strip 500 x 2 == 1000 times
            for (var t = 0; t < (testCount / 2); t++)
            {
                bkColor     = RGBHelper.Wheel(wheelIndex);
                wheelIndex += 2;
                if (wheelIndex >= 256)
                {
                    wheelIndex = 0;
                }

                // Light up in red the 60 led strips
                ledStrip.Reset();
                for (var l = 0; l < ledStrip.MaxLed; l++)
                {
                    ledStrip.AddRGBSequence(false, 7, bkColor);
                }
                ledStrip.Show();

                // Turn it off the 60 led strips
                ledStrip.Reset();
                for (var l = 0; l < ledStrip.MaxLed; l++)
                {
                    ledStrip.AddRGBSequence(false, 7, Color.Black);
                }
                ledStrip.Show();
            }

            sw.Stop();
            var bytePerSeconds = ledStrip.MaxLed * 4 * testCount / (sw.ElapsedMilliseconds / 1000);

            Console.WriteLine("test Duration:{0}, BytePerSecond:{1}, NumberOfLedTurnOnOrOff:{2}",
                              sw.ElapsedMilliseconds,
                              bytePerSeconds,
                              ledStrip.MaxLed * testCount
                              );
            var k = Console.ReadKey(true).Key;

            ledStrip.AllOff();
            k = Console.ReadKey(true).Key;
        }
Beispiel #6
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;
        }
Beispiel #7
0
        public static void BrigthnessDemo(APA102LEDStrip ledStrip0, APA102LEDStrip ledStrip1)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Brightness Demo", ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 3, "Q)uit");

            ledStrip0.AllOff();
            ledStrip1.AllOff();
            var bkColors = TargetColors.Replace(Environment.NewLine, ",").Split(',').ToList();
            var wait     = 15;

            while (!Console.KeyAvailable)
            {
                foreach (var sBColor in bkColors)
                {
                    var bkColor = APA102LEDStrip.DrawingColors[sBColor];

                    for (var b = 1; b <= APA102LEDStrip.MAX_BRIGHTNESS; b += 2)
                    {
                        ConsoleEx.Write(1, 2, string.Format("Brightness {0:00}", b), ConsoleColor.DarkCyan);
                        ledStrip0.SetColor(b, bkColor).Show();
                        ledStrip1.SetColor(b, bkColor).Show().Wait(wait);
                    }

                    if (Console.KeyAvailable)
                    {
                        break;
                    }
                    ledStrip0.Wait(wait * 10); // Wait when the fade in is done

                    for (var b = APA102LEDStrip.MAX_BRIGHTNESS; b >= 0; b -= 2)
                    {
                        ConsoleEx.Write(1, 2, string.Format("Brightness {0:00}", b), ConsoleColor.DarkCyan);
                        ledStrip0.SetColor(b, bkColor).Show();
                        ledStrip1.SetColor(b, bkColor).Show().Wait(wait);
                    }

                    if (Console.KeyAvailable)
                    {
                        break;
                    }
                    ledStrip0.Wait(wait * 10); // Wait when the fade out is deon
                }
            }
            ledStrip0.AllOff();
            ledStrip1.AllOff();
            var k = Console.ReadKey(true).Key;
        }
Beispiel #8
0
        public static void LineDemo(APA102LEDStrip ledStripe)
        {
            int wait = 20;
            var quit = false;

            ledStripe.AllOff();
            Console.Clear();
            ConsoleEx.WriteMenu(-1, 4, "Q)uit");

            while (!quit)
            {
                var j = 0;

                for (var i = 0; i < ledStripe.MaxLed; i++)
                {
                    var bkColor = RGBHelper.Wheel(((i * 256 / ledStripe.MaxLed) + j));
                    ledStripe.AddRGBSequence(true, 2, i + 1, bkColor);
                    if (++j >= 256)
                    {
                        j = 0;
                    }
                    while (!ledStripe.IsFull)
                    {
                        ledStripe.AddRGBSequence(false, 2, Color.Black);
                    }

                    ledStripe.Show().Wait(wait);

                    Console.WriteLine(String.Format("Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)));

                    if (Console.KeyAvailable)
                    {
                        while (Console.KeyAvailable)
                        {
                            var k = Console.ReadKey(true).Key;
                            if (k == ConsoleKey.Q)
                            {
                                quit = true;
                                break;
                            }
                        }
                    }
                }
                ledStripe.Wait(wait * 3).AllOff();
            }
            ledStripe.AllOff();
        }
Beispiel #9
0
        public static void RainbowDemo2(APA102LEDStrip ledStrip, int jStep)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Rainbow Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            int brigthness = 6;
            int wait       = GetWaitTimeUnit(ledStrip) / 2;
            var quit       = false;

            ledStrip.AllOff();

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

                    for (var i = 0; i < ledStrip.MaxLed; i++)
                    {
                        ledStrip.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)));
                    }
                    ledStrip.Show().Wait(wait);
                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                            break;
                        }
                    }
                }
            }
            ledStrip.AllOff();
        }
Beispiel #10
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);
 }
Beispiel #11
0
        /// <summary>
        ///
        /// *** ATTENTION ***
        ///
        /// WHEN CONTROLLING AN APA LED STRIP WITH NUSBIO YOU MUST KNOW THE AMP CONSUMPTION.
        ///
        /// USB DEVICE ARE LIMITED TO 500 MILLI AMP.
        ///
        /// AN LED IN GENERAL CONSUMES FROM 20 TO 25 MILLI AMP. AN RGB LED CONSUMES 3 TIMES
        /// MORE IF THE RED, GREEN AND BLUE ARE SET TO THE 255, 255, 255 WHICH IS WHITE
        /// AT THE MAXIMUN INTENSISTY WHICH IS 31.
        ///
        /// YOU MUST KNOW WHAT IS THE MAXIMUN CONSUMPTION OF YOUR APA 102 RGB LEB STRIP WHEN THE
        /// RGB IS SET TO WHITE, WHITE, WHITE AND THE BRIGTHNESS IS AT THE MAXIMUM.
        ///
        ///    -------------------------------------------------------------------------------
        ///    --- NEVER GO OVER 300 MILLI AMP IF THE LED STRIP IS POWERED FROM THE NUSBIO ---
        ///    -------------------------------------------------------------------------------
        ///
        ///         POWER ONLY A LED STRIP OF 5 LED WHEN DIRECTLY PLUGGED INTO NUSBIO.
        ///
        /// THE FUNCTION AmpTest() WILL LIGHT UP THE FIRST LED OF THE STRIP AT MAXIMUM BRIGHTNESS.
        /// USE A MULTI METER TO WATCH THE AMP COMSUMPTION.
        ///
        /// IF YOU WANT TO POWER MORE THAN 5 LEDS, THERE ARE 2 SOLUTIONS:
        ///
        /// (1) ONLY FOR 6 to 10 LEDs. ADD BETWEEN NUSBIO VCC AND THE STRIP 5V PIN A 47 OHM RESISTORS.
        /// YOU WILL LOOSE SOME BRIGTHNESS, BUT IT IS SIMPLER. THE RESISTOR LIMIT THE CURRENT THAT
        /// CAN BE USED FROM THE USB.
        ///
        /// (2) USE A SECOND SOURCE OF POWER LIKE:
        ///
        ///  - A 5 VOLTS 1 AMPS ADAPTERS TO POWER A 30 LED STRIP
        ///  - A 5 VOLTS 2 AMPS ADAPTERS TO POWER A 60 LED STRIP
        ///
        /// ~~~ ATTENTION ~~~
        ///
        ///     WHEN USING A SECOND SOURCE OF POWER IN THE SAME BREADBOARD OR PCB, ~ NEVER ~
        ///     CONNECT THE POSISTIVE OF THE SECOND SOURCE OF POWER WITH THE NUSBIO VCC.
        ///
        /// SEE OUR WEB SITE 'LED STRIP TUTORIAL' FOR MORE INFO.
        ///
        /// </summary>
        /// <param name="ledStrip"></param>
        public static void AmpTest(APA102LEDStrip ledStrip)
        {
            int wait          = 37;
            var brightness    = 1;
            var maxBrightness = APA102LEDStrip.MAX_BRIGHTNESS / 2; // 7
            var quit          = false;

            ledStrip.AllOff();

            while (!quit)
            {
                Console.Clear();
                ConsoleEx.TitleBar(0, "Amp Consumption Test ");
                ConsoleEx.WriteMenu(-1, 2, string.Format("Brigthness:{0}  I)ncrease  D)ecrease", brightness));
                ConsoleEx.WriteMenu(-1, 3, "Q)uit");

                ledStrip.Reset();
                ledStrip.AddRGBSequence(true, brightness, ledStrip.MaxLed, Color.White);
                ledStrip.Show();

                var k = Console.ReadKey().Key;
                switch (k)
                {
                case ConsoleKey.Q: quit = true; break;

                case ConsoleKey.I:
                    brightness++;
                    if (brightness > maxBrightness)
                    {
                        brightness = maxBrightness;
                    }
                    break;

                case ConsoleKey.D:
                    brightness--;
                    if (brightness < 0)
                    {
                        brightness = 0;
                    }
                    break;
                }
            }
            ledStrip.AllOff();
        }
Beispiel #12
0
        public static void ColorsSequence(APA102LEDStrip ledStripe0, APA102LEDStrip ledStripe1)
        {
            var wait = 300;
            var quit = false;

            ledStripe0.Brightness = 7;
            ledStripe0.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Color Sequence Demo", ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 4, "Q)uit");

            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];
                    ConsoleEx.Gotoxy(1, 2);
                    ConsoleEx.WriteLine(string.Format("Background Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)), ConsoleColor.DarkCyan);

                    ledStripe0.Reset().AddRGBSequence(true, ledStripe0.Brightness, ledStripe0.MaxLed, bkColor).Show();
                    ledStripe1.Reset().AddRGBSequence(true, ledStripe1.Brightness, ledStripe0.MaxLed, bkColor).Show().Wait(wait);

                    if (Console.KeyAvailable)
                    {
                        quit = true;
                        break;
                    }
                }
            }
            ledStripe0.AllOff();
            var k = Console.ReadKey(true).Key;
        }
Beispiel #13
0
        public static void MultiShades(APA102LEDStrip ledStrip)
        {
            int wait = 0;
            var quit = false;

            ledStrip.AllOff();

            while (!quit)
            {
                for (var j = 0; j < 256; j++)
                {
                    Console.Clear();
                    ledStrip.Reset();

                    for (var i = 0; i < ledStrip.MaxLed; i++)
                    {
                        ledStrip.AddRGBSequence(false, 10, RGBHelper.Wheel(((i + j))));
                    }

                    foreach (var bkColor in ledStrip.LedColors)
                    {
                        Console.WriteLine(String.Format("Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)));
                    }

                    ledStrip.Show().Wait(wait);

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                            break;
                        }
                    }
                }
            }
            ledStrip.AllOff();
        }
Beispiel #14
0
        public static void BrigthnessDemo(APA102LEDStrip ledStrip)
        {
            int maxBrightness = APA102LEDStrip.MAX_BRIGHTNESS / 2;
            int wait          = GetWaitTimeUnit(ledStrip) / 2;
            int step          = 1;

            ledStrip.AllOff();
            Console.Clear();
            ConsoleEx.WriteMenu(-1, 3, "Q)uit");
            while (!Console.KeyAvailable)
            {
                for (var b = 1; b <= maxBrightness; b += step)
                {
                    ledStrip.Reset();
                    for (var l = 0; l < ledStrip.MaxLed; l++)
                    {
                        if (!ledStrip.IsFull)
                        {
                            ledStrip.AddRGB(Color.Red, b);
                        }
                        if (!ledStrip.IsFull)
                        {
                            ledStrip.AddRGB(Color.Green, b);
                        }
                        if (!ledStrip.IsFull)
                        {
                            ledStrip.AddRGB(Color.Blue, b);
                        }
                    }
                    ConsoleEx.Write(0, 0, string.Format("Brightness {0:00}", b), ConsoleColor.DarkCyan);
                    ledStrip.Show().Wait(wait);
                }
                ledStrip.Wait(wait * 10);
                for (var b = maxBrightness; b >= 1; b -= step)
                {
                    ledStrip.Reset();
                    for (var l = 0; l < ledStrip.MaxLed; l++)
                    {
                        if (!ledStrip.IsFull)
                        {
                            ledStrip.AddRGB(Color.Red, b);
                        }
                        if (!ledStrip.IsFull)
                        {
                            ledStrip.AddRGB(Color.Green, b);
                        }
                        if (!ledStrip.IsFull)
                        {
                            ledStrip.AddRGB(Color.Blue, b);
                        }
                    }
                    ConsoleEx.Write(0, 0, string.Format("Brightness {0:00}", b), ConsoleColor.DarkCyan);
                    ledStrip.Show().Wait(wait);
                }
                //ledStrip.AllOff();
                ledStrip.Wait(wait * 10);
                if (Console.KeyAvailable)
                {
                    break;
                }
            }
            ledStrip.AllOff();
            var k = Console.ReadKey(true).Key;
        }
Beispiel #15
0
        public static void RainbowDemo(APA102LEDStrip ledStrip0, int jStep, APA102LEDStrip ledStrip1, bool inSync)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Rainbow Demo", ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 6, "Q)uit");

            int wait       = 13;
            var quit       = false;
            var maxStep    = 256;
            var brightness = 16;

            ledStrip0.AllOff();
            ledStrip1.AllOff();

            while (!quit)
            {
                var j2 = maxStep;
                for (var j = 0; j < maxStep; j += jStep)
                {
                    if (inSync) // If in sync both led show the same color else show opposite color
                    {
                        j2 = j;
                    }

                    ledStrip0.Reset();
                    ledStrip1.Reset();

                    for (var i = 0; i < ledStrip0.MaxLed; i++)
                    {
                        ledStrip0.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j)));
                    }

                    for (var i = 0; i < ledStrip1.MaxLed; i++)
                    {
                        ledStrip1.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j2)));
                    }

                    foreach (var bkColor in ledStrip0.LedColors)
                    {
                        ConsoleEx.WriteLine(1, 2, String.Format("Strip 0 - Color:{0}, Html:{1}, Dec:{2}, WheelIndex:{3}      ", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor), j), ConsoleColor.DarkCyan);
                    }
                    foreach (var bkColor in ledStrip1.LedColors)
                    {
                        ConsoleEx.WriteLine(1, 3, String.Format("Strip 1 - Color:{0}, Html:{1}, Dec:{2}, WheelIndex:{3}", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor), j2), ConsoleColor.DarkCyan);
                    }

                    ledStrip0.Show();
                    ledStrip1.Show().Wait(wait);

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                            break;
                        }
                    }
                    j2--;
                }
            }
            ledStrip0.AllOff();
            ledStrip1.AllOff();
        }
Beispiel #16
0
        public static void Run(string[] args)
        {
            Console.WriteLine("Nusbio initialization x64:{0}", Environment.Is64BitProcess);

            var serialNumber = Nusbio.Detect();

            if (serialNumber == null) // Detect the first Nusbio available
            {
                Console.WriteLine("nusbio not detected");
                return;
            }

            //
            // Nusbio Extension - 2 RGB LED Panel
            //
            // For more information about the Nusbio APA102 2 Strip Adapter to control up to 2 strips
            // with 10 RGB LED on each strip powered from Nusbio. See following url
            // http://www.madeintheusb.net/TutorialExtension/Index#Apa102RgbLedStrip

            using (var nusbio = new Nusbio(serialNumber))
            {
                Cls(nusbio);
                APA102LEDStrip ledStrip0 = APA102LEDStrip.Extensions.TwoStripAdapter.Init(nusbio, APA102LEDStrip.Extensions.LedPerMeter._1Led, APA102LEDStrip.Extensions.StripIndex._0, 1);
                APA102LEDStrip ledStrip1 = APA102LEDStrip.Extensions.TwoStripAdapter.Init(nusbio, APA102LEDStrip.Extensions.LedPerMeter._1Led, APA102LEDStrip.Extensions.StripIndex._1, 1);

                while (nusbio.Loop())
                {
                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            break;
                        }

                        if (k == ConsoleKey.B)
                        {
                            BrigthnessDemo(ledStrip0, ledStrip1);
                        }

                        if (k == ConsoleKey.C)
                        {
                            ComboWith6LedPanel(nusbio, ledStrip0, ledStrip1);
                        }

                        if (k == ConsoleKey.R)
                        {
                            RainbowDemo(ledStrip0, 1, ledStrip1, false);
                        }

                        if (k == ConsoleKey.W)
                        {
                            RainbowDemo(ledStrip0, 1, ledStrip1, true);
                        }

                        if (k == ConsoleKey.F)
                        {
                            RainbowDemo(ledStrip0, 8, ledStrip1, true);
                        }

                        if (k == ConsoleKey.S)
                        {
                            ColorsSequence(ledStrip0, ledStrip1);
                        }

                        if (k == ConsoleKey.T)
                        {
                            TrigonometrieOneColorDemo(ledStrip1);
                        }

                        if (k == ConsoleKey.L)
                        {
                            LineDemo(ledStrip0);
                        }

                        Cls(nusbio);
                    }
                }
            }
            Console.Clear();
        }
Beispiel #17
0
        public static void Run(string[] args)
        {
            Console.WriteLine("Nusbio initialization");
            var serialNumber = Nusbio.Detect();

            if (serialNumber == null) // Detect the first Nusbio available
            {
                Console.WriteLine("nusbio not detected");
                return;
            }
            Console.Clear();

            using (var nusbio = new Nusbio(serialNumber))
            {
                // Communication optimization for the SPI protocol where there is no MISO (Master In Slave Out).
                // We can reduce the amount of data sent. The performance below will vary depending on the PC overall performance.
                // There are 2 options. Both option cannot be combined.
                // - No optimization:13.7kb/s
                // - CompactData:16.7kb/s is safe but only get an 21% improvement at best and is data dependent.
                // - CombineSPIDataAndClockOnSameCycle:19.5kb/s may work with APA102 RGB LED, will not work with regular SPI component

                //APA102LEDStrip.CompactData                       = true;
                APA102LEDStrip.CombineSPIDataAndClockOnSameCycle = true;

                var ledPerMeter = AskForStripType();
                var ledCount    = AskForLedCount();

                // 30 led per meter strip
                APA102LEDStrip ledStrip0 = APA102LEDStrip.Extensions.TwoStripAdapter.Init(nusbio, ledPerMeter, APA102LEDStrip.Extensions.StripIndex._0, ledCount);
                ledStrip0.AllOff();
                Cls(nusbio);

                // For more information about the Nusbio APA102 2 Strip Adapter to control up to 2 strips
                // with 10 RGB LED on each strip powered from Nusbio. See following url
                // http://www.madeintheusb.net/TutorialExtension/Index#Apa102RgbLedStrip

                APA102LEDStrip ledStrip1 = APA102LEDStrip.Extensions.TwoStripAdapter.Init(nusbio, ledPerMeter, APA102LEDStrip.Extensions.StripIndex._1, ledCount);
                if (ledStrip1 != null)
                {
                    ledStrip1.AllOff();
                }

                while (nusbio.Loop())
                {
                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            break;
                        }

                        if (k == ConsoleKey.R)
                        {
                            RGBDemo(ledStrip0);
                        }

                        if (k == ConsoleKey.B)
                        {
                            BrigthnessDemo(ledStrip0);
                        }

                        if (k == ConsoleKey.A)
                        {
                            AmpTest(ledStrip0);
                        }

                        if (k == ConsoleKey.W)
                        {
                            RainbowDemo(ledStrip0, 6, ledStrip1);
                        }

                        if (k == ConsoleKey.M)
                        {
                            MultiShades(ledStrip0);
                        }

                        if (k == ConsoleKey.S)
                        {
                            ScrollDemo(ledStrip0);
                        }

                        if (k == ConsoleKey.D1)
                        {
                            TrigonometrieOneColorDemo(ledStrip0);
                        }

                        if (k == ConsoleKey.D2)
                        {
                            TrigonometrieMultiColorEvolutionDemo(ledStrip0);
                        }

                        if (k == ConsoleKey.P)
                        {
                            PerformanceTest(ledStrip0);
                        }

                        if (k == ConsoleKey.L)
                        {
                            LineDemo(ledStrip0);
                        }

                        if (k == ConsoleKey.C)
                        {
                            PhotoRainbowDemo(ledStrip0, 1, -1, ledStrip1);
                        }

                        Cls(nusbio);
                    }
                }
            }
            Console.Clear();
        }
Beispiel #18
0
        public static void AlternateLineDemo(APA102LEDStrip ledStrip)
        {
            var wait = GetWaitTimeUnit(ledStrip);

            if (ledStrip.MaxLed <= 10)
            {
                wait *= 3;
            }

            var quit = false;

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

            Console.Clear();
            ConsoleEx.TitleBar(0, "Alternate Line 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.ToBrighter(APA102LEDStrip.DrawingColors[sBColor], -75);

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

                    ledStrip.Reset();
                    for (var l = 0; l < ledStrip.MaxLed; l += 2)
                    {
                        ledStrip.AddRGBSequence(false, 4, bkColor);
                        ledStrip.AddRGBSequence(false, 6, fgColor);
                    }

                    for (var i = 0; i < ledStrip.MaxLed * 3; i += 4)
                    {
                        ledStrip.Show().ShiftRightSequence().Wait(wait);
                        if (Console.KeyAvailable)
                        {
                            break;
                        }
                    }

                    if (Console.KeyAvailable)
                    {
                        quit = true;
                        break;
                    }
                }
            }
            ledStrip.AllOff();
            var k = Console.ReadKey(true).Key;
        }
Beispiel #19
0
        private static int GetWaitTimeUnit(APA102LEDStrip ledStrip)
        {
            var wait = (int)((80.0 / (2 * ledStrip.MaxLed)) * 10);

            return(wait);
        }
Beispiel #20
0
        public static void TrigonometrieMultiColorEvolutionDemo(APA102LEDStrip ledStrip)
        {
            APA102LEDStrip.CombineSPIDataAndClockOnSameCycle = true;

            var wait = GetWaitTimeUnit(ledStrip);

            if (ledStrip.MaxLed <= 10)
            {
                wait *= 3;
            }

            var maxLed = ledStrip.MaxLed;
            var quit   = false;

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

            Console.Clear();
            ConsoleEx.TitleBar(0, "Trigonometrie Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            var trigoCircleMax  = Math.PI / 2;
            var amplitude       = 4;
            var amplitudeStep   = 0.1;
            var amplitudeFactor = amplitudeStep;

            amplitudeFactor = 1;

            var minPhaseOffSet  = 0.0;
            var maxPhaseOffSet  = Math.PI;
            var phaseOffSetStep = maxPhaseOffSet / 100;
            var phaseOffSet     = 0.0;

            var _4Sin3_div_3PI = RGBHelper.GenerateTrigonometricValues(maxLed, trigoCircleMax,
                                                                       radianV => (amplitudeFactor * amplitude) * Math.Sin((3 * radianV)) / (3 * Math.PI),
                                                                       colorMinValue: 128, diplayData: true);

            var _4Sin5_div_5PI_Phase2 = RGBHelper.GenerateTrigonometricValues(maxLed, trigoCircleMax,
                                                                              radianV => (amplitudeFactor * amplitude) * Math.Sin((5 * radianV)) / (5 * Math.PI),
                                                                              colorMinValue: 128, diplayData: true);

            var _4Sin7_div_7PI_Phase3 = RGBHelper.GenerateTrigonometricValues(maxLed, trigoCircleMax,
                                                                              radianV => (amplitudeFactor * amplitude) * Math.Sin((7 * radianV)) / (7 * Math.PI),
                                                                              colorMinValue: 128, diplayData: true);

            List <System.Drawing.Color> colorVariation = null;
            int loopIndex = 0;

            while (!quit)
            {
                Console.WriteLine("amplitudeFactor:{0}, phaseOffSet:{1}", amplitudeFactor, phaseOffSet);

                switch (loopIndex % 3)
                {
                case 0: colorVariation = RGBHelper.GenerateListOfColor(maxLed, _4Sin3_div_3PI, _4Sin5_div_5PI_Phase2, null); break;

                case 1: colorVariation = RGBHelper.GenerateListOfColor(maxLed, _4Sin3_div_3PI, null, _4Sin5_div_5PI_Phase2); break;

                case 2: colorVariation = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin3_div_3PI, _4Sin5_div_5PI_Phase2); break;
                }
                //loopIndex += 1;

                if (!PlayTrigonometrieVariation(ledStrip, wait, colorVariation, "Experiment", 1))
                {
                    break;
                }

                //amplitudeFactor += amplitudeStep;
                if (amplitudeFactor > 3)
                {
                    amplitudeFactor = amplitudeStep;
                }

                //phaseOffSet = phaseOffSet + phaseOffSetStep;
                //if (phaseOffSet > maxPhaseOffSet)
                //    phaseOffSet = minPhaseOffSet;

                if (Console.KeyAvailable)
                {
                    if (Console.ReadKey().Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }
            }
            ledStrip.AllOff();
        }
Beispiel #21
0
        public static void ComboWith6LedPanel(Nusbio nusbio, APA102LEDStrip ledStrip0, APA102LEDStrip ledStrip1 = null)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Rainbow Demo", ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 6, "Q)uit");

            int wait       = 50;
            var quit       = false;
            var maxStep    = 256;
            var brightness = 5;
            int jStep      = 8;

            ledStrip0.AllOff();
            ledStrip1.AllOff();

            var ledIndex        = -1;
            var maxLedIndex     = 4;
            var ledIndexTimeOut = new TimeOut(wait * 50);

            while (!quit)
            {
                var j2 = maxStep;
                for (var j = 0; j < maxStep; j += jStep)
                {
                    ledStrip0.Reset();
                    ledStrip1.Reset();

                    for (var i = 0; i < ledStrip0.MaxLed; i++)
                    {
                        ledStrip0.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j)));
                    }

                    for (var i = 0; i < ledStrip1.MaxLed; i++)
                    {
                        ledStrip1.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j2)));
                    }

                    foreach (var bkColor in ledStrip0.LedColors)
                    {
                        ConsoleEx.WriteLine(1, 2, String.Format("Strip 0 - Color:{0}, Html:{1}, Dec:{2}", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)), ConsoleColor.DarkCyan);
                    }
                    foreach (var bkColor in ledStrip1.LedColors)
                    {
                        ConsoleEx.WriteLine(1, 3, String.Format("Strip 1 - Color:{0}, Html:{1}, Dec:{2}", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)), ConsoleColor.DarkCyan);
                    }
                    j2 -= jStep;
                    if (j2 < 0)
                    {
                        j2 = maxStep;
                    }

                    ledStrip0.Show();
                    ledStrip1.Show().Wait(wait);

                    /*
                     * // Turn on and off led connected to gpio 0,1,2,3
                     * if (ledIndexTimeOut.IsTimeOut())
                     * {
                     *  if (ledIndex != -1)
                     *      nusbio[ledIndex].Low();
                     *  ledIndex++;
                     *  if (ledIndex == maxLedIndex)
                     *      ledIndex = 0;
                     *  nusbio[ledIndex].High();
                     * }
                     */

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                            break;
                        }
                    }
                }
            }
            ledStrip0.AllOff();
            ledStrip1.AllOff();
        }