Andy A / miniFont

Dependents:   WS2812Text

You are viewing an older revision! See the latest version

Homepage

A basic low resolution font

This font is intened 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() {
    
    char characterData[5];
    char letter = 'x'
    
    if (myFont.getChar(letter,&characterData)) {
        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 (characterData[row] & (0x01<<col)) 
               printf("1");
             else
               printf("0");
             }
             printf("\n");
           }
        }
    }

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 capitalised. Not tested excessively, if you find any problems please let me know.


All wikipages