A low resolution font for LED matrix displays e.g. neopixels
A basic low resolution font
This font is intend for very low resolution display systems e.g. LED matrix displays. All characters are 5 pixels high and 5 or less pixels wide.
Data for a given character is returned as an array of 5 chars each char represents one row of the image reading from the top down. The least significant 5 bits of each char represent the pixels on that line.
e.g. For the letter X the returned data is { 0x11, 0x0a, 0x04, 0x0a, 0x11 } As bits this translates to
- 10001
- 01010
- 00100
- 01010
- 10001
The following code will output the bit pattern for the selected character.
#include "miniFont.h" miniFont myFont; int main() { const char **charData = NULL; char letter = 'x'; if (myFont.getChar(letter,charData)) { for (int row = 0; row < myFont.getPixHeight(letter); row++) { for (int col = myFont.getPixWidth(letter) - 1; col >= 0; col--) { // start at the left not the right if ( *(*charData + row) & (0x01<<col)) printf("1"); else printf("0"); } printf("\n"); } } }
Note - In order to avoid pointless copying of data getChar modifies the value in the supplied char to point to the start of the character array. However in some situations this means that the data will only be valid until the next time getChar is called. If you need to keep the data longer than that make a copy.
Characters are right justified, e.g. if getWidth() returns a value of 3 then only the 3 least significant bits of each row contain data. There are options to force fixed width characters (narrow characters will be shifted to the middle of a 5 pixel width) and to rotate characters 90 degrees Supported characters are A-Z 0-9 . ! ? <space> Any lower case letters are automatically capitalized. Not tested excessively, if you find any problems please let me know.
History
Documentation and example updated
2014-11-07, by AndyA [Fri, 07 Nov 2014 09:38:54 +0000] rev 1
Documentation and example updated
Added comments/doucmentation
2014-11-07, by AndyA [Fri, 07 Nov 2014 09:24:10 +0000] rev 0
Added comments/doucmentation