Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            LedDisplay display = new LedDisplay(32, 16, SerialPort.GetPortNames()[0]);

            display.OpenSerial();

            display.SetBrightness(120);
            display.FillDisplay(LedColor.White);
            display.RefreshDisplay();
            Thread.Sleep(1000);

            Console.WriteLine("Drawing Lines");
            display.DrawLine(0, 0, 5, 10, LedColor.Red);
            display.DrawLine(5, 0, 10, 10, LedColor.Green);
            display.DrawLine(10, 0, 15, 10, LedColor.Blue);
            display.RefreshDisplay();
            Thread.Sleep(1000);

            Console.WriteLine("Drawing circles");
            display.ClearDisplay();
            display.DrawCircle(12, 6, 5, LedColor.Yellow);
            display.RefreshDisplay();
            Thread.Sleep(1000);

            Console.WriteLine("Drawing rectangles");
            display.ClearDisplay();
            display.DrawRectangle(0, 0, 10, 12, LedColor.Orange, LedColor.Cyan);
            display.DrawRectangle(15, 0, 18, 4, LedColor.Purple);
            display.RefreshDisplay();
            Thread.Sleep(1000);


            Console.WriteLine("Drawing text");
            String time = DateTime.Now.ToString("HH:mm");

            display.ClearDisplay();
            display.DrawString(0, 0, LedColor.Blue, time, 0, Fonts.Font6X8);
            display.RefreshDisplay();

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            LedDisplay display = new LedDisplay(32, 16, SerialPort.GetPortNames()[0]);

            display.OpenSerial();

            display.DrawBitmap(new Bitmap("bitmap.bmp"), 0, 0, 32, 16);
            display.RefreshDisplay();

            for (byte i = 255; i > 0; i -= 5)
            {
                Console.WriteLine("Brightness: " + i);
                display.SetBrightness(i);
                Thread.Sleep(250);
            }
        }
        static void Main(string[] args)
        {
            LedDisplay display = new LedDisplay(32, 16, SerialPort.GetPortNames()[0]);

            display.OpenSerial();
            display.SetBrightness(175);

            while (true)
            {
                display.ClearDisplay();

                String time = DateTime.Now.ToString("HH:mm");
                display.DrawString(0, 4, LedColor.Red, time, 0, Fonts.Font6X8);

                display.RefreshDisplay();
                Thread.Sleep(2000);
            }
        }
        static void Main(string[] args)
        {
            int  frames    = 5000;
            bool benchmark = true; // Set to false if you want to loop forever

            LedDisplay display = new LedDisplay(32, 16, SerialPort.GetPortNames()[0]);

            display.OpenSerial();

            // Prepare pallete
            LedColor[] palette = new LedColor[360];
            for (int x = 0; x < 360; x++)
            {
                int r, g, b;
                HsvToRgb(x, 1.0, 1.0, out r, out g, out b);
                palette[x] = new LedColor {
                    R = (byte)r,
                    G = (byte)g,
                    B = (byte)b
                };
            }

            int[,] cls = null;
            int start = Environment.TickCount;
            int i     = 0;

            while (i < frames)
            {
                int w = 32;
                int h = 16;

                if (cls == null)
                {
                    cls = new int[w, h];
                    for (int x = 0; x < w; x++)
                    {
                        for (int y = 0; y < h; y++)
                        {
                            cls[x, y] = (int)(
                                128.0 + (128.0 * Math.Sin(x / 2.0))
                                + 128.0 + (128.0 * Math.Sin(y / 4.0))
                                + 128.0 +
                                (128.0 * Math.Sin(Math.Sqrt(((x - w / 2.0) * (x - w / 2.0) + (y - h / 2.0) * (y - h / 2.0))) / 2.0))
                                + 128.0 + (128.0 * Math.Sin(Math.Sqrt((x * x + y * y)) / 2.0))
                                ) / 4;
                        }
                    }
                }

                int paletteShift = Convert.ToInt32(Environment.TickCount / 5);
                for (int x = 0; x < w; x++)
                {
                    for (int y = 0; y < h; y++)
                    {
                        display.DrawPixel(x, y, palette[(cls[x, y] + paletteShift) % 360]);
                    }
                }

                display.RefreshDisplay();
                if (benchmark)
                {
                    i++;
                }
            }

            int    elapsed   = Environment.TickCount - start;
            double fps       = frames / (elapsed / 1000.0);
            double bits      = (fps * ((32 * 16 * 3) + 1) * 8) / 1000;
            double bandwidth = (bits / 12000) * 100;

            Console.WriteLine("Time elapsed: " + elapsed);
            Console.WriteLine("Frames per second: " + fps);
            Console.WriteLine("kb/s: " + bits + " (" + bandwidth + "% of maximum theoritical serial output)");
            Console.ReadKey();
        }