Exemple #1
0
    static void Main()
    {
        IPConnection      ipcon = new IPConnection();                // Create IP connection
        BrickletOLED64x48 oled  = new BrickletOLED64x48(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT);                                   // Connect to brickd
        // Don't use device before ipcon is connected

        // Clear display
        oled.ClearDisplay();

        // Draw checkerboard pattern
        bool[][] pixels = new bool[HEIGHT][];

        for (int row = 0; row < HEIGHT; row++)
        {
            pixels[row] = new bool[WIDTH];

            for (int column = 0; column < WIDTH; column++)
            {
                pixels[row][column] = (row / 8) % 2 == (column / 8) % 2;
            }
        }

        DrawMatrix(oled, pixels);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Exemple #2
0
    private static void DrawMatrix(BrickletOLED64x48 oled, bool[][] pixels)
    {
        byte[][] pages = new byte[HEIGHT / 8][];

        for (int row = 0; row < HEIGHT / 8; row++)
        {
            pages[row] = new byte[WIDTH];

            for (int column = 0; column < WIDTH; column++)
            {
                pages[row][column] = 0;

                for (int bit = 0; bit < 8; bit++)
                {
                    if (pixels[(row * 8) + bit][column])
                    {
                        pages[row][column] |= (byte)(1 << bit);
                    }
                }
            }
        }

        oled.NewWindow(0, (byte)(WIDTH - 1), 0, (byte)(HEIGHT / 8 - 1));

        for (int row = 0; row < HEIGHT / 8; row++)
        {
            oled.Write(pages[row]);
        }
    }
    private static void DrawBitmap(BrickletOLED64x48 oled, Bitmap bitmap)
    {
        byte[][] pages = new byte[HEIGHT / 8][];

        for (int row = 0; row < HEIGHT / 8; row++)
        {
            pages[row] = new byte[WIDTH];

            for (int column = 0; column < WIDTH; column++)
            {
                pages[row][column] = 0;

                for (int bit = 0; bit < 8; bit++)
                {
                    if (bitmap.GetPixel(column, (row * 8) + bit).GetBrightness() > 0)
                    {
                        pages[row][column] |= (byte)(1 << bit);
                    }
                }
            }
        }

        oled.NewWindow(0, (byte)(WIDTH - 1), 0, (byte)(HEIGHT / 8 - 1));

        for (int row = 0; row < HEIGHT / 8; row++)
        {
            oled.Write(pages[row]);
        }
    }
Exemple #4
0
    private static string UID  = "XYZ";    // Change XYZ to the UID of your OLED 64x48 Bricklet

    static void Main()
    {
        IPConnection      ipcon = new IPConnection();                // Create IP connection
        BrickletOLED64x48 oled  = new BrickletOLED64x48(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT);                                   // Connect to brickd
        // Don't use device before ipcon is connected

        // Clear display
        oled.ClearDisplay();

        // Write "Hello World" starting from upper left corner of the screen
        oled.WriteLine(0, 0, "Hello World");

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
    static void Main()
    {
        IPConnection      ipcon = new IPConnection();                // Create IP connection
        BrickletOLED64x48 oled  = new BrickletOLED64x48(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT);                                   // Connect to brickd
        // Don't use device before ipcon is connected

        // Clear display
        oled.ClearDisplay();

        // Draw rotating line
        Bitmap bitmap  = new Bitmap(WIDTH, HEIGHT);
        int    originX = WIDTH / 2;
        int    originY = HEIGHT / 2;
        int    length  = HEIGHT / 2 - 2;
        int    angle   = 0;

        Console.WriteLine("Press enter to exit");

        while (!Console.KeyAvailable)
        {
            double radians = Math.PI * angle / 180.0;
            int    x       = (int)(originX + length * Math.Cos(radians));
            int    y       = (int)(originY + length * Math.Sin(radians));

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.FillRectangle(Brushes.Black, 0, 0, WIDTH, HEIGHT);
                g.DrawLine(Pens.White, originX, originY, x, y);
            }

            DrawBitmap(oled, bitmap);
            Thread.Sleep(25);

            angle++;
        }

        Console.ReadLine();
        ipcon.Disconnect();
    }