Hi All,
I am missing something small I think in adding a font to GLCD. I have located a suitable font and run it through GLCD FontCreator2 to produce the following file.
/*
*
* new Font
*
* created with FontCreator
* written by F. Maximilian Thiele
*
* http://www.apetech.de/fontCreator
* me@apetech.de
*
* File Name : baby
* Date : 28.07.2013
* Font size in bytes : 6394
* Font width : 5
* Font height : 13
* Font first char : 32
* Font last char : 128
* Font used chars : 96
*
* The font data are defined as
*
* struct _FONT_ {
* uint16_t font_Size_in_Bytes_over_all_included_Size_it_self;
* uint8_t font_Width_in_Pixel_for_fixed_drawing;
* uint8_t font_Height_in_Pixel_for_all_characters;
* unit8_t font_First_Char;
* uint8_t font_Char_Count;
*
* uint8_t font_Char_Widths[font_Last_Char - font_First_Char +1];
* // for each character the separate width in pixels,
* // characters < 128 have an implicit virtual right empty row
*
* uint8_t font_data[];
* // bit field of all characters
*/
#include <inttypes.h>
#include <avr/pgmspace.h>
#ifndef NEW_FONT_H
#define NEW_FONT_H
#define NEW_FONT_WIDTH 5
#define NEW_FONT_HEIGHT 13
static uint8_t new_Font[] PROGMEM = {
0x18, 0xFA, // size
0x05, // width
0x0D, // height
0x20, // first char
0x60, // char count
// char widths
0x00, 0x02, 0x04, 0x07, 0x04, 0x07, 0x07, 0x01, 0x03, 0x03,
0x04, 0x05, 0x03, 0x04, 0x01, 0x04, 0x04, 0x03, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x02, 0x03, 0x06, 0x04,
0x06, 0x06, 0x07, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x04, 0x06, 0x06, 0x04, 0x07, 0x06, 0x06, 0x06, 0x06,
0x06, 0x04, 0x04, 0x06, 0x07, 0x07, 0x06, 0x06, 0x06, 0x03,
0x04, 0x03, 0x04, 0x06, 0x03, 0x06, 0x06, 0x04, 0x06, 0x06,
0x06, 0x06, 0x06, 0x01, 0x03, 0x04, 0x01, 0x07, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x04, 0x06, 0x06, 0x07, 0x06, 0x06,
0x06, 0x04, 0x01, 0x04, 0x07, 0x07,
// font data
0x7C, 0x7C, 0x10, 0x10, // 33
0x1F, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, // 34
0xB0, 0xF8, 0xF8, 0xB0, 0xF8, 0xF8, 0xB0, 0x08, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, // 35
0x30, 0x5C, 0x5C, 0x98, 0x10, 0x30, 0x30, 0x08, // 36
0x38, 0xB8, 0xB8, 0x40, 0xB0, 0xB8, 0x98, 0x10, 0x08, 0x08, 0x00, 0x18, 0x18, 0x18, // 37
0xD8, 0x34, 0x34, 0x58, 0x80, 0x80, 0x00, 0x08, 0x10, 0x10, 0x10, 0x08, 0x18, 0x10, // 38
0x1F, 0x00, // 39
0xF8, 0x04, 0x04, 0x18, 0x20, 0x20, // 40
0x04, 0xF8, 0xF8, 0x20, 0x18, 0x18, // 41
0x34, 0x18, 0x18, 0x34, 0x00, 0x00, 0x00, 0x00, // 42
0x40, 0x40, 0xF0, 0x40, 0x40, 0x00, 0x00, 0x08, 0x00, 0x00, // 43
0x00, 0x00, 0x00, 0xD0, 0x30, 0x30, // 44
0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, // 45
0x00, 0x10, // 46
0x00, 0xC0, 0xC0, 0x38, 0x30, 0x08, 0x08, 0x00, // 47
0xF0, 0x18, 0x18, 0xF0, 0x08, 0x10, 0x10, 0x08, // 48
some data omitted for brevity
0xF8, 0xF8, 0x58, 0x68, 0x68, 0xF8, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 // 127
};
#endif
To my unpracticed eye this looks OK.
I have edited allFonts.h to look like this:
/*
* allFonts.h font header for GLCD library
* The fonts listed below will be available in a sketch if this file is included
*
* If you create your own fonts you can add the header to this file
*
* Note that the build environment only holds a font in Flash if its selected
* so there is no penalty to including a font file here if its not used
*/
#include "SystemFont5x7.h" // system font
#include "Arial14.h" // proportional font
#include "Arial_bold_14.h" // Bold proportional font
#include "Corsiva_12.h"
#include "Verdana_digits_24.h" // large proportional font - numerals only
#include "fixednums7x15.h" // fixed width font - numerals only
#include "fixednums8x16.h" // fixed width font - numerals only
#include "fixednums15x31.h" // fixed width font - numerals only
#include "newFont.h" // small proportional font
and then edited the GLCD hello world example to look like this:
/*
GLCD Library - Hello World
This sketch prints "Hello World!" to the LCD
and shows the time in seconds since reset.
The circuit:
See the inlcuded documentation in glcd/doc directory for how to wire
up the glcd module. glcd/doc/GLCDref.htm can be viewed in your browser
by clicking on the file.
*/
// include the library header
#include <glcd.h>
// include the Fonts
#include <fonts/allFonts.h>
void setup() {
// Initialize the GLCD
GLCD.Init();
// Select the font for the default text area
GLCD.SelectFont(newFont);
GLCD.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
GLCD.CursorTo(0, 1);
// print the number of seconds since reset:
GLCD.print(millis()/1000);
}
Now if the font is the original SystemFont5x7 is used this compiles just fine. But with newFont the compiler tells me this:
HelloWorld.cpp: In function 'void setup()':
HelloWorld.pde:-1: error: 'newFont' was not declared in this scope
I am missing something simple I think. But what.
Thanks, Fred.