Exemplo n.º 1
0
        private static void DrawRoundRectDemo(NusbioMatrix matrix, int wait, int maxRepeat, int deviceIndex)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Draw Round Rectangle Demo");

            matrix.CurrentDeviceIndex = deviceIndex;

            for (byte rpt = 0; rpt <= maxRepeat; rpt += 2)
            {
                matrix.Clear(deviceIndex);
                var yy = 0;
                while (yy <= 3)
                {
                    matrix.DrawRoundRect(yy, yy, 8 - (yy * 2), 8 - (yy * 2), 2, 1);
                    matrix.CopyToAll(deviceIndex, true);
                    TimePeriod.Sleep(wait);
                    yy += 1;
                }
                TimePeriod.Sleep(wait);
                yy = 2;
                while (yy >= 0)
                {
                    matrix.DrawRoundRect(yy, yy, 8 - (yy * 2), 8 - (yy * 2), 2, 0);
                    matrix.CopyToAll(deviceIndex, true);
                    TimePeriod.Sleep(wait);
                    yy -= 1;
                }
                matrix.Clear(deviceIndex);
                matrix.CopyToAll(deviceIndex, true);
                TimePeriod.Sleep(wait);
            }
        }
Exemplo n.º 2
0
        private static void DrawRectDemo(NusbioMatrix matrix, int MAX_REPEAT, int wait, int deviceIndex)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Draw Rectangle Demo");
            ConsoleEx.WriteMenu(0, 2, "Q)uit");

            matrix.Clear(deviceIndex);
            matrix.CopyToAll(deviceIndex, refreshAll: true);
            matrix.CurrentDeviceIndex = deviceIndex;

            for (byte rpt = 0; rpt < MAX_REPEAT; rpt += 3)
            {
                matrix.Clear();
                var y = 0;
                while (y <= 4)
                {
                    matrix.DrawRect(y, y, 8 - (y * 2), 8 - (y * 2), true);
                    matrix.CopyToAll(deviceIndex, refreshAll: true);
                    TimePeriod.Sleep(wait);
                    y += 1;
                }
                TimePeriod.Sleep(wait);
                y = 4;
                while (y >= 1)
                {
                    matrix.DrawRect(y, y, 8 - (y * 2), 8 - (y * 2), false);
                    matrix.CopyToAll(deviceIndex, refreshAll: true);
                    TimePeriod.Sleep(wait);
                    y -= 1;
                }
            }
            matrix.Clear(deviceIndex);
        }
Exemplo n.º 3
0
        static void DisplayImageSequence(NusbioMatrix matrix, string title, int deviceIndex, int maxRepeat, int wait, List <List <string> > images)
        {
            matrix.CurrentDeviceIndex = deviceIndex;
            Console.Clear();
            ConsoleEx.TitleBar(0, title);
            ConsoleEx.WriteMenu(0, 2, "Q)uit");

            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.CopyToAll(deviceIndex, refreshAll: true);
                    TimePeriod.Sleep(wait);

                    if (Console.KeyAvailable)
                    {
                        if (Console.ReadKey().Key == ConsoleKey.Q)
                        {
                            return;
                        }
                    }
                }
            }
            matrix.Clear(deviceIndex, refresh: true);
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        private static void DrawAllMatrixOnePixelAtTheTimeDemo(NusbioMatrix matrix, int deviceIndex, int waitAfterClear = 350, int maxRepeat = 4)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Draw one pixel at the time demo");
            ConsoleEx.WriteMenu(0, 2, "Q)uit");
            ConsoleEx.WriteLine(0, ConsoleUserStatusRow + 1, "".PadLeft(80), ConsoleColor.Black);
            ConsoleEx.Gotoxy(0, ConsoleUserStatusRow + 1);

            for (byte rpt = 0; rpt < maxRepeat; rpt++)
            {
                matrix.Clear(deviceIndex, refresh: true);
                TimePeriod.Sleep(waitAfterClear);
                for (var r = 0; r < matrix.Height; r++)
                {
                    for (var c = 0; c < matrix.Width; c++)
                    {
                        matrix.CurrentDeviceIndex = deviceIndex;
                        matrix.DrawPixel(r, c, true);
                        // Only refresh the row when we light up an led
                        // This is 8 time faster than a full refresh
                        matrix.WriteRow(deviceIndex, r);
                        Console.Write('.');
                    }
                }
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        private static void DrawCircleDemo(NusbioMatrix matrix, int wait, int deviceIndex)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "DrawCircle Demo");

            matrix.CurrentDeviceIndex = deviceIndex;
            matrix.Clear(deviceIndex);
            matrix.CopyToAll(deviceIndex, refreshAll: true);

            var circleLocations = new List <Coordinate>()
            {
                new Coordinate {
                    X = 4, Y = 4
                },
                new Coordinate {
                    X = 3, Y = 3
                },
                new Coordinate {
                    X = 5, Y = 5
                },
                new Coordinate {
                    X = 2, Y = 2
                },
            };

            foreach (var circleLocation in circleLocations)
            {
                for (byte ray = 0; ray <= 4; ray++)
                {
                    matrix.Clear(deviceIndex);
                    matrix.DrawCircle(circleLocation.X, circleLocation.Y, ray, 1);
                    matrix.CopyToAll(deviceIndex, refreshAll: true);
                    TimePeriod.Sleep(wait);
                }
            }
        }
Exemplo n.º 12
0
        private static void DrawOnePixelAllOverTheMatrixDemo(NusbioMatrix matrix, int deviceIndex, int waitAfterClear = 350, int maxRepeat = 4)
        {
            ConsoleEx.Bar(0, ConsoleUserStatusRow, "DrawPixel Demo", ConsoleColor.Yellow, ConsoleColor.Red);

            for (byte rpt = 0; rpt < maxRepeat; rpt++)
            {
                for (var r = 0; r < matrix.Height; r++)
                {
                    for (var c = 0; c < matrix.Width; c++)
                    {
                        matrix.Clear(deviceIndex);
                        matrix.CurrentDeviceIndex = deviceIndex;
                        matrix.DrawPixel(r, c, true);


                        // Only refresh the row when we light up an led
                        // This is 8 time faster than a full refresh
                        matrix.WriteRow(deviceIndex, r);
                        Thread.Sleep(32);
                    }
                }
            }
            matrix.Clear(deviceIndex);
        }
Exemplo n.º 13
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();
        }
Exemplo n.º 14
0
        private static void LandscapeDemo(NusbioMatrix matrix, int deviceIndex = 0)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Random Landscape Demo");
            ConsoleEx.WriteMenu(0, 2, "Q)uit  F)ull speed");
            var landscape = new NusbioLandscapeMatrix(matrix, 0);

            var speed = 250 - (matrix.DeviceCount * 25); // slower speed if we have 1 device rather than 4

            if (matrix.DeviceCount == 1)
            {
                speed = 150;
            }

            matrix.Clear(all: true);
            var quit      = false;
            var fullSpeed = false;

            while (!quit)
            {
                landscape.Redraw();

                ConsoleEx.WriteLine(0, 4, landscape.ToString(), ConsoleColor.Cyan);
                if (!fullSpeed)
                {
                    Thread.Sleep(speed);
                }

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

                    case ConsoleKey.F:
                        fullSpeed = !fullSpeed; break;
                    }
                }
            }
        }
Exemplo n.º 15
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();
        }
Exemplo n.º 16
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));
                        }
                    }
                }
            }
        }