Adding Multiple Fonts and Sizes for use with the OLED
Overview: Now that you know how to use fonts other than the ones that come shipped with the BCore Operating System, here’s how to add even more for use at the same time!
Steps:
For Data2, let's use the 24pt version of the font CNB. Copy and Paste the following line of code to declare the font.
DATA UFONT(23560) FROMFILE "CNB24.bin"
23560 is the declared size of the font file in word format. (1 Word = 2 Bytes = 16bit)
Check out the font file's size by looking at its property and divide it by 2.
Let's proceed to download the font file into the DataFlash chip. With DATA2 selected, you should see the following buttons above the project explorer pane.
In the project explorer pane, click on CODE1. To use the 24pt font that is stored in DATA2, we'll need to add the following 3 lines of code to the previous program.
PTR = DFlash.AddressOf(DATA2.UFONT) OLED.USERFONT.INIT(PTR) OLED.Print "FONT 24 " 'LARGE FONTS SIZE 24
So the entire program will look like this:
'CODE1 Dim PTR As Long '=============================================================================== Public Sub Main() Debug.Print "Fonts" OLED.Init(Const.Color.Black) OLED.Orientation = 0 'OLED.Print "Font 123" 'NORMAL FONTS SIZE 8 OLED.FontType = 3 PTR = DFlash.AddressOf(DATA1.UFONT) OLED.USERFONT.INIT(PTR) OLED.Print "FONT 32" 'LARGE FONTS SIZE 32 PTR = DFlash.AddressOf(DATA2.UFONT) OLED.USERFONT.INIT(PTR) OLED.Print "FONT 24 " 'LARGE FONTS SIZE 24 End Sub
Note: UserFont is currently not showing up under syntax helper as a member of OLED in the current version of Sonata, but this ought to change in the subsequent releases of Sonata.
Finally, "Compile and Download" the project. (Shortcut: F5)
That should give you 2 lines of 2 different font sizes on the screen.
TIP: Should you have an error while downloading, try pressing the white reset button on the BCore100 Board, and try again.
To get your screen looking like the image above where it's using even more fonts, you'll need to keep adding more Data Files to the project until it looks like this;
Declare the font files and compile+download them into the DataFlash Chip.
You can download a full project here where this is already done for you. Of course, you'll need to compile and download each Data File before you can see the fonts. |





