# How to parse array to x,y positions?

I have 16x16 LED matrix and I want to show some custom characters on it. I saw font made with array like this.

``````const byte zero = { // Create byte array number 0
B0111110,
B1111111,
B1100011,
B1100011,
B1100011,
B1100011,
B1100011,
B1100011,
B1100011,
B1100011,
B1100011,
B1100011,
B1100011,
B1100011,
B1111111,
B0111110
};
``````

But I dont know how to parse it to x, y positions. Can someone help me? Do you know better way to store characters that is easily readable by human? Thanks

To get the value at a particular location, use this code:

``````boolean val = zero[y] & ((B1 << maxX) >> x);
``````

where `y` is the y position from 0 to `zero.length`, `maxX` is the length of the binary constants minus one (in this case, it would be 6), and `x` is the x position from 0 to `maxX`.

• That code looks promising. I will try it :) Nov 3, 2014 at 21:59
• Is it possible to get that maximum x and maximum y from array? I want to make it functional with any size of array(character). Nov 3, 2014 at 22:08
• @Antoan See my edit. I would suggest that you make all the byte arrays have the same width, e.g. seven. Nov 3, 2014 at 22:38
• Nice thanks. But is it posssible to get maxX from my array? Like it will check zero and by that it knows its 7 bits long. Is it possible? Nov 3, 2014 at 22:51
• I tried this code: `for(int x = 0; x < 7; x++){ for(int y = 0; y < 16; y++){ boolean val = zero[y] & (B1000000 >> x); if(val == 1){ Pixel(x,y,1); } } }` but it only shows 7th bit. Where I made mistake? Nov 3, 2014 at 23:06

Th example looks like the character '0', 8 bits wide and 16 bits high, though it could be the 16x8 due to '0's symmetry. Find the '2' array, for instance and plot the 1-bits on a piece of graph paper (even a hand-drawn grid will do). Once you should see the character shape you'll know how the bits/dots are arranged in the array.

If your LED array has a square pitch (same spacing vertically and horizontally), 16-bit high characters may appear rather tall and skinny. If so, you could re-plot the characters to suit yourself. If you do decide to hand code them, look at your display hardware. It probably (but not necessarily) accepts 8 horizontally-adjacent bits at a time. But regardless, you can simplify your display code if one array-byte contains 8 bits that will be output at once.

--------- Update:

There's a lot missing from your question but I'll pick some assumptions to base an answer on.

``````Y = array_index;
X = (6-bit_position) + (is_right_hand_character ? 8 : 0);
``````

based on assumptions that:

• you want the display coordinates of a given bit in the array;
• the origin (0,0) of your display is the upper left hand corner LED;
• the first character starts in column 0; the second in column 8; The leftmost bit to display is in bit-6 of each byte and bit 7 (MSb) is not used;
• you'll use zero-based coordinates.

The 'Y' coordinate is pretty straight-forward - byte-0 is the first byte. The 'X' coordinate is found by subtracting the position of the bit of interest from 6, and maybe adding 8, since bit-6 goes into column-0 or column-8 for the left or right character, respectively.

• That 0 is my character I want to display on matrix. I want to display 2 numbers on it so thats why I use 7x16 size. I just want to know how to get x,y positions from array like that. Nov 3, 2014 at 21:28