Ejemplo n.º 1
0
        private static void RotateMatrix(NusbioMatrix matrix, int deviceIndex)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Rotate Demo");
            ConsoleEx.WriteMenu(0, 2, "Rotate:  L)eft  R)ight  Q)uit");

            matrix.Clear(deviceIndex);
            matrix.CurrentDeviceIndex = deviceIndex;
            matrix.DrawLine(0, 0, 0, matrix.Height, true);
            matrix.DrawLine(7, 0, 7, matrix.Height, true);
            matrix.DrawLine(0, 2, matrix.Width, 2, true);
            matrix.WriteDisplay(deviceIndex);

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

                case ConsoleKey.L: matrix.RotateLeft(deviceIndex); break;

                case ConsoleKey.R: matrix.RotateRight(deviceIndex); break;
                }
                matrix.WriteDisplay(deviceIndex);
            }
        }
Ejemplo n.º 2
0
        static void ScrollDemo(NusbioMatrix matrix, int deviceIndex)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Scroll Demo");
            ConsoleEx.WriteMenu(0, 2, "Q)uit");

            matrix.Clear(all: true, refresh: true);

            for (var d = 0; d < matrix.DeviceCount; d++)
            {
                for (var x = 0; x < matrix.Width; x++)
                {
                    matrix.SetLed(d, x, 0, true);
                    matrix.SetLed(d, x, 7, true);
                    matrix.SetLed(d, 0, x, true);
                }
            }
            matrix.WriteDisplay(all: true);
            Thread.Sleep(1000);

            for (var z = 0; z < 8 * 3; z++)
            {
                matrix.ScrollPixelLeftDevices(3, 0);
                matrix.WriteDisplay(all: true);
            }
        }
Ejemplo n.º 3
0
        static void  PerformanceTest(NusbioMatrix matrix, int deviceIndex)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Performance Test");
            ConsoleEx.WriteLine(0, 2, "Drawing images as fast as possible", ConsoleColor.Cyan);

            int maxRepeat = 16;

            matrix.CurrentDeviceIndex = deviceIndex;

            var images = new List <List <string> > {
                Square00Bmp, Square02Bmp
            };

            ConsoleEx.WriteLine(0, 3, "Slow mode first", ConsoleColor.Cyan);
            ConsoleEx.Gotoxy(0, 4);
            for (byte rpt = 0; rpt < maxRepeat; rpt++)
            {
                foreach (var image in images)
                {
                    matrix.Clear(deviceIndex, refresh: false);
                    matrix.DrawBitmap(0, 0, image, 8, 8, 1);
                    matrix.WriteDisplay(deviceIndex);
                    Console.Write(".");
                    Thread.Sleep(200);
                }
            }

            maxRepeat = 128;

            ConsoleEx.WriteLine(0, 5, "Fast mode first", ConsoleColor.Cyan);
            ConsoleEx.Gotoxy(0, 6);
            matrix.BytesSentOutCounter = 0;
            var sw = Stopwatch.StartNew();
            int writeDisplayCount = 0;

            for (byte rpt = 0; rpt < maxRepeat; rpt++)
            {
                foreach (var image in images)
                {
                    matrix.Clear(deviceIndex, refresh: false);
                    matrix.DrawBitmap(0, 0, image, 8, 8, 1);
                    matrix.WriteDisplay(deviceIndex);
                    writeDisplayCount++;
                    Console.Write(".");
                }
            }
            Console.WriteLine("");
            Console.WriteLine("Display Refresh:{0}, {1:0.0} Refresh/S, Bytes Sent:{2}, {3:0.0} K Byte/S",
                              writeDisplayCount,
                              writeDisplayCount * 1000.0 / sw.ElapsedMilliseconds,
                              matrix.BytesSentOutCounter,
                              matrix.BytesSentOutCounter / (sw.ElapsedMilliseconds / 1000.0) / 1024.0
                              );
            sw.Stop();
            Console.WriteLine("Hit any key to continue");
            var k = Console.ReadKey();
        }
Ejemplo n.º 4
0
        private static void BrightnessDemo(NusbioMatrix matrix, int maxRepeat, int deviceIndex)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Brightness Demo");

            matrix.Clear(deviceIndex);
            matrix.CurrentDeviceIndex = deviceIndex;

            var y = 0;

            for (y = 0; y < matrix.Height; y++)
            {
                matrix.DrawLine(0, y, matrix.Width, y, true);
                matrix.WriteDisplay(deviceIndex);
            }
            matrix.AnimateSetBrightness(maxRepeat - 2, deviceIndex: deviceIndex);
            matrix.Clear(deviceIndex);
        }
Ejemplo n.º 5
0
        static void DisplayImage(NusbioMatrix matrix)
        {
            int MAX_REPEAT = 3;
            int wait       = 400;

            ConsoleEx.Bar(0, ConsoleUserStatusRow, "DrawBitmap Demo", ConsoleColor.Yellow, ConsoleColor.Red);
            for (byte rpt = 0; rpt < MAX_REPEAT; rpt++)
            {
                var images = new List <List <string> > {
                    neutralBmp, smileBmp, neutralBmp, frownbmp
                };
                foreach (var image in images)
                {
                    matrix.Clear(refresh: false);
                    matrix.DrawBitmap(0, 0, BitUtil.ParseBinary(image), 8, 8, 1);
                    matrix.WriteDisplay();
                    TimePeriod.Sleep(wait);
                }
            }
            matrix.Clear();
        }
Ejemplo n.º 6
0
        static void test11(NusbioMatrix matrix)
        {
            matrix.Clear(0);
            Thread.Sleep(500);
            for (var r = 0; r < 8; r++)
            {
                for (var c = 0; c < 8; c++)
                {
                    matrix.SetLed(0, r, c, true, true);  // WriteDisplay for every pixel
                }
            }
            Thread.Sleep(500);

            matrix.Clear(0);
            Thread.Sleep(500);
            for (var r = 0; r < 8; r++)
            {
                for (var c = 0; c < 8; c++)
                {
                    matrix.SetLed(0, r, c, true, c == 7); // WriteDisplay for every row
                }
            }
            Thread.Sleep(500);

            matrix.Clear(0);
            Thread.Sleep(500);
            for (var r = 0; r < 8; r++)
            {
                for (var c = 0; c < 8; c++)
                {
                    matrix.SetLed(0, r, c, true, false);
                }
            }
            matrix.WriteDisplay(); // WriteDisplay only once
            Thread.Sleep(500);
        }
Ejemplo n.º 7
0
        private static void DrawAxis(NusbioMatrix matrix, int deviceIndex)
        {
            ConsoleEx.Bar(0, ConsoleUserStatusRow, "Draw Axis Demo", ConsoleColor.Yellow, ConsoleColor.Red);

            Console.Clear();
            ConsoleEx.TitleBar(0, "Draw Axis Demo");
            ConsoleEx.WriteMenu(0, 2, "Q)uit");


            matrix.Clear(deviceIndex);
            matrix.CurrentDeviceIndex = deviceIndex;

            matrix.Clear(deviceIndex);
            matrix.CurrentDeviceIndex = deviceIndex;
            matrix.DrawLine(0, 0, matrix.Width, 0, true);
            matrix.DrawLine(0, 0, 0, matrix.Height, true);
            matrix.WriteDisplay(deviceIndex);

            for (var i = 0; i < matrix.Width; i++)
            {
                matrix.SetLed(deviceIndex, i, i, true, true);
            }
            var k = Console.ReadKey();
        }
Ejemplo n.º 8
0
        // Testing MAX7219 to control 10 led bar
        // It is partially working as I can control MAX7219 SegA (8 led) or SegB (2 led)
        // But because only 10 led are wired instead of the 64, this affect the multiplexing
        // and in the end we cannot have the 10 led on at the same time
        static void test1(NusbioMatrix matrix)
        {
            //matrix.Clear(0, refresh: true);
            //for (var r = 0; r < 8; r++)
            //    for (var c = 0; c < 8; c++)
            //        matrix.SetLed(0, r, c, true, true); // WriteDisplay for every pixel
            //Thread.Sleep(500);

            matrix.Clear(0, refresh: true);
            matrix.SetPixel(0, (byte)(32));
            matrix.SetPixel(1, (byte)(32));
            matrix.WriteDisplay();

            matrix.Clear(0, refresh: true);
            for (var p = 0; p < 8; p++)
            {
                matrix.SetPixel(p, (byte)(64));
                matrix.WriteDisplay();
            }
            matrix.WriteDisplay();

            matrix.SetPixel(0, (byte)(64 + 32));
            matrix.SetPixel(1, (byte)(64 + 32));
            matrix.WriteDisplay();


            matrix.Clear(0, refresh: true);
            for (var p = 0; p < 8; p++)
            {
                matrix.SetPixel(p, (byte)(255));
                matrix.WriteDisplay();
            }
            matrix.WriteDisplay();

            matrix.Clear(0, refresh: true);
            for (var b = 0; b < 8; b++)
            {
                for (var p = 0; p < 8; p++)
                {
                    matrix.SetPixel(p, (byte)(1 << b));
                    matrix.WriteDisplay();
                }
            }
            Thread.Sleep(500);
            matrix.Clear(0, refresh: false);
            matrix.WriteDisplay();

            matrix.Clear(0, refresh: true);
            for (var r = 0; r < 8; r++)
            {
                for (var c = 0; c < 8; c++)
                {
                    matrix.SetLed(0, r, c, true, false); // WriteDisplay for every pixel
                }
            }
            Thread.Sleep(500);
            matrix.WriteDisplay(0);

            var m = new MAX7219MapTo10LedBarMap(matrix);
            m.Clear(true);
            for (var i = 0; i < m.Count; i++)
            {
                m.SetState(i, true, true);
            }
            m.WriteDisplay();
        }
Ejemplo n.º 9
0
        private static void ScrollText(NusbioMatrix matrix, int deviceIndex = 0)
        {
            var quit  = false;
            var speed = 10;
            var text  = "Hello World!   ";

            if (matrix.DeviceCount == 1 && matrix.MAX7219Wiring == NusbioMatrix.MAX7219_WIRING_TO_8x8_LED_MATRIX.OriginBottomRightCorner)
            {
                speed = speed * 3;
            }

            while (!quit)
            {
                Console.Clear();
                ConsoleEx.TitleBar(0, "Scroll Text");
                ConsoleEx.WriteMenu(0, 2, string.Format("Q)uit  F)aster  S)lower   Speed:{0:000}", speed));

                matrix.Clear(all: true);
                matrix.WriteDisplay(all: true);

                for (var ci = 0; ci < text.Length; ci++)
                {
                    var c = text[ci];

                    ConsoleEx.WriteMenu(ci, 4, c.ToString());

                    matrix.WriteChar(deviceIndex, c); // See property matrix.MAX7218Wiring for more info
                    matrix.WriteDisplay(all: true);

                    if (speed > 0)
                    {
                        Thread.Sleep(speed);
                        // Provide a better animation
                        if (matrix.DeviceCount == 1 && matrix.MAX7219Wiring == NusbioMatrix.MAX7219_WIRING_TO_8x8_LED_MATRIX.OriginBottomRightCorner)
                        {
                            Thread.Sleep(speed * 12);
                        }
                    }

                    for (var i = 0; i < MAX7219.MATRIX_ROW_SIZE; i++)
                    {
                        matrix.ScrollPixelLeftDevices(matrix.DeviceCount - 1, 0, 1);
                        matrix.WriteDisplay(all: true);

                        // Do not wait when we scrolled the last pixel, we will wait when we display the new character
                        if (i < MAX7219.MATRIX_ROW_SIZE - 1)
                        {
                            if (speed > 0)
                            {
                                Thread.Sleep(speed);
                            }
                        }

                        if (Console.KeyAvailable)
                        {
                            switch (Console.ReadKey().Key)
                            {
                            case ConsoleKey.Q: quit = true; i = 100; ci = 10000; break;

                            case ConsoleKey.S: speed += 10; break;

                            case ConsoleKey.F: speed -= 10; if (speed < 0)
                                {
                                    speed = 0;
                                }
                                break;
                            }
                            ConsoleEx.WriteMenu(0, 2, string.Format("Q)uit  F)aster  S)lower   Speed:{0:000}", speed));
                        }
                    }
                }
            }
        }