Poduzov/PI4J-I2C-LCD

How to create custom characters

bzc0fq opened this issue · 1 comments

Hi,

I'm new in Java world, but I use your library in my project and so far - it works fine.
I have one question about load_custom_chars .

// add custom characters(0 - 7)
    private void load_custom_chars(byte[][] fontdata) {

        lcd_write((byte) 0x40);
        for (int i = 0; i < fontdata.length; i++) {
            for (int j = 0; j < fontdata[i].length; j++) {
                write_char(fontdata[i][j]);
            }
        }
    }

Could you please advice on how to use it?
I tried to do a byte array with test values, but it failed at compilation stage.

It would be nice if you could send an example how to create custom characters using your code.

Many thanks for helping.

Best Regards

It would be nice if you could send an example how to create custom characters using your code.

OK. I have figured this out... here what I have done:

byte [][] new_chars = {
               {0x00, 0x0E, 0x15, 0x15, 0x17, 0x11, 0x0E, 0x00},       // 0x00 clock
               {0x10, 0x10, 0x14, 0x08, 0x17, 0x10, 0x10, 0x10},       // 0x01 satelite
               {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F},       // 0x02 battery 100%
               {0x0E, 0x1B, 0x11, 0x11, 0x1F, 0x1F, 0x1F, 0x1F},       // 0x03 battery 50%
               {0x0E, 0x1B, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x1F},       // 0x04 battery 15%
               {0x0E, 0x1B, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F},       // 0x05 battery 0%
               {0x1F, 0x04, 0x0E, 0x15, 0x04, 0x04, 0x04, 0x04},       // 0x06 collision detection front
               {0x04, 0x04, 0x04, 0x04, 0x15, 0x0E, 0x04, 0x1F},       // 0x07 collision detection back
                                };

load_custom_chars(new_chars);
display_string_pos("", 3, 3); //move cursor somewhere...
write_char((byte) 0x02);    //write character #2 -> battery 100%

I am not sure I do it in right way, if not - please correct me if I am wrong...