I have a 5x8 Neopixel shield for my Arduino. I want to display text on it, while it is in "landscape mode", i.e. a only 5pt high text. The default font that is used by the print
command is 8pt high. How can I load a font with 5pt height into my code?
I understand that the Neopixel library depends on Adafruit GFX
, which allows for different fonts. But changing the font according to the Adafruit tutorial on GFX to one of the supplied fonts does not return any readable text (only a moving line of dots). I found this font converter and used it to produce a 5pt font, but again only a moving dot appears.
This is my code (basically the Neomatrix example with modified orientation of the matrix):
// Adafruit_NeoMatrix example for single NeoPixel Shield.
// Scrolls 'Howdy' across the matrix in a portrait (vertical) orientation.
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include <Fonts/Dialog_plain_5.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif
#define PIN 6
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 5, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT+
NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,
NEO_GRBW + NEO_KHZ800);
const uint16_t colors[] = {
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
void setup() {
matrix.setFont(&Dialog_plain_5);
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(30);
matrix.setTextColor(colors[0]);
}
int x = matrix.width();
int pass = 0;
void loop() {
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print(F("Howdy"));
if(--x < -36) {
x = matrix.width();
if(++pass >= 3) pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
delay(100);
}
and this is the content of the font file:
// Created by http://oleddisplay.squix.ch/ Consider a donation
// In case of problems make sure that you are using the font file with the correct version!
const uint8_t Dialog_plain_5Bitmaps[] PROGMEM = {
// Bitmap Data:
0x00, // ' '
0xF0, // '!'
0xC0, // '"'
0x07,0xF2, // '#'
0x79,0xF4, // '$'
0xD1,0x10,0xB0, // '%'
0x88,0xCA, // '&'
0x80, // '''
0x2A,0x00, // '('
0x15,0x00, // ')'
0x08,0x00, // '*'
0x01,0x1C,0x40, // '+'
0x00, // ','
0xC0, // '-'
0x00, // '.'
0x6A,0x00, // '/'
0xD6,0xE0, // '0'
0xC9,0x20, // '1'
0x62,0x48, // '2'
0xE8,0xE0, // '3'
0x26,0x62, // '4'
0x08,0x90, // '5'
0x7A,0xE0, // '6'
0x25,0x20, // '7'
0xEA,0xE0, // '8'
0xD5,0xE0, // '9'
0x00, // ':'
0x00, // ';'
0x02,0xC6, // '<'
0x77, // '='
0x06,0x16, // '>'
0xD0, // '?'
0x27,0xB7,0x66,0x00, // '@'
0x4A,0x68, // 'A'
0xFA,0xD0, // 'B'
0x68,0x86, // 'C'
0xE9,0x9A, // 'D'
0xDA,0x40, // 'E'
0x9A,0x40, // 'F'
0x78,0xB5, // 'G'
0xBE,0xD0, // 'H'
0xF0, // 'I'
0x55,0x40, // 'J'
0xAC,0xCA, // 'K'
0x92,0x40, // 'L'
0x9F,0xF9, // 'M'
0xBF,0xD0, // 'N'
0x69,0x96, // 'O'
0xF7,0x40, // 'P'
0x69,0x96,0x00, // 'Q'
0xEA,0xCA, // 'R'
0x91,0x60, // 'S'
0x21,0x08,0x40, // 'T'
0xB6,0xE0, // 'U'
0xAA,0xA4, // 'V'
0xAF,0xBC,0xA0, // 'W'
0xA4,0x4A, // 'X'
0x53,0x08,0x40, // 'Y'
0x64,0x88, // 'Z'
0xAA,0x80, // '['
0xAA,0x40, // '\'
0x55,0x40, // ']'
0x61, // '^'
0x70, // '_'
0x00, // '`'
0xDE,0x80, // 'a'
0x9A,0xE0, // 'b'
0x92,0x00, // 'c'
0x3E,0xD0, // 'd'
0xDE,0x00, // 'e'
0x49,0x20, // 'f'
0xF6,0xA0, // 'g'
0x9E,0xD0, // 'h'
0xF0, // 'i'
0x55,0x40, // 'j'
0x9A,0x60, // 'k'
0xF0, // 'l'
0xFD,0x6A, // 'm'
0xF6,0x80, // 'n'
0xD7,0x00, // 'o'
0xD7,0x40, // 'p'
0xF6,0xB0, // 'q'
0x2A, // 'r'
0x4C,0x80, // 's'
0x49,0x20, // 't'
0x16,0xD0, // 'u'
0xB9,0x00, // 'v'
0xD7,0x60, // 'w'
0xCB,0x00, // 'x'
0xB9,0x40, // 'y'
0x68, // 'z'
0x4A,0x24, // '{'
0xF8, // '|'
0x48,0xA4 // '}'
};
const GFXglyph Dialog_plain_5Glyphs[] PROGMEM = {
// bitmapOffset, width, height, xAdvance, xOffset, yOffset
{ 0, 1, 1, 3, 0, 0 }, // ' '
{ 1, 1, 4, 3, 0, -4 }, // '!'
{ 2, 2, 2, 3, 0, -4 }, // '"'
{ 3, 4, 4, 5, 0, -4 }, // '#'
{ 5, 3, 5, 4, 0, -4 }, // '$'
{ 7, 5, 4, 6, 0, -4 }, // '%'
{ 10, 4, 4, 5, 0, -4 }, // '&'
{ 12, 1, 2, 2, 0, -4 }, // '''
{ 13, 2, 5, 3, 0, -4 }, // '('
{ 15, 2, 5, 3, 0, -4 }, // ')'
{ 17, 3, 3, 4, 0, -4 }, // '*'
{ 19, 5, 4, 6, 0, -4 }, // '+'
{ 22, 2, 3, 3, 0, -2 }, // ','
{ 23, 2, 1, 3, 0, -2 }, // '-'
{ 24, 2, 1, 3, 0, -1 }, // '.'
{ 25, 2, 5, 3, 0, -4 }, // '/'
{ 27, 3, 4, 4, 0, -4 }, // '0'
{ 29, 3, 4, 4, 0, -4 }, // '1'
{ 31, 4, 4, 4, 0, -4 }, // '2'
{ 33, 3, 4, 4, 0, -4 }, // '3'
{ 35, 4, 4, 5, 0, -4 }, // '4'
{ 37, 3, 4, 4, 0, -4 }, // '5'
{ 39, 3, 4, 4, 0, -4 }, // '6'
{ 41, 3, 4, 4, 0, -4 }, // '7'
{ 43, 3, 4, 4, 0, -4 }, // '8'
{ 45, 3, 4, 4, 0, -4 }, // '9'
{ 47, 2, 3, 3, 0, -3 }, // ':'
{ 48, 2, 4, 3, 0, -3 }, // ';'
{ 49, 4, 4, 5, 1, -4 }, // '<'
{ 51, 4, 2, 5, 0, -3 }, // '='
{ 52, 4, 4, 5, 0, -4 }, // '>'
{ 54, 2, 4, 4, 0, -4 }, // '?'
{ 55, 5, 5, 6, 0, -4 }, // '@'
{ 59, 4, 4, 4, 0, -4 }, // 'A'
{ 61, 3, 4, 4, 0, -4 }, // 'B'
{ 63, 4, 4, 4, 0, -4 }, // 'C'
{ 65, 4, 4, 5, 0, -4 }, // 'D'
{ 67, 3, 4, 4, 0, -4 }, // 'E'
{ 69, 3, 4, 4, 0, -4 }, // 'F'
{ 71, 4, 4, 5, 0, -4 }, // 'G'
{ 73, 3, 4, 4, 0, -4 }, // 'H'
{ 75, 1, 4, 2, 0, -4 }, // 'I'
{ 76, 2, 5, 2, -1, -4 }, // 'J'
{ 78, 4, 4, 4, 0, -4 }, // 'K'
{ 80, 3, 4, 4, 0, -4 }, // 'L'
{ 82, 4, 4, 5, 0, -4 }, // 'M'
{ 84, 3, 4, 4, 0, -4 }, // 'N'
{ 86, 4, 4, 5, 0, -4 }, // 'O'
{ 88, 3, 4, 4, 0, -4 }, // 'P'
{ 90, 4, 5, 5, 0, -4 }, // 'Q'
{ 93, 4, 4, 4, 0, -4 }, // 'R'
{ 95, 3, 4, 5, 1, -4 }, // 'S'
{ 97, 5, 4, 4, -1, -4 }, // 'T'
{ 100, 3, 4, 4, 0, -4 }, // 'U'
{ 102, 4, 4, 4, 0, -4 }, // 'V'
{ 104, 5, 4, 6, 0, -4 }, // 'W'
{ 107, 4, 4, 4, 0, -4 }, // 'X'
{ 109, 5, 4, 4, -1, -4 }, // 'Y'
{ 112, 4, 4, 6, 1, -4 }, // 'Z'
{ 114, 2, 5, 3, 0, -4 }, // '['
{ 116, 2, 5, 3, 0, -4 }, // '\'
{ 118, 2, 5, 3, 0, -4 }, // ']'
{ 120, 4, 2, 5, 0, -4 }, // '^'
{ 121, 4, 1, 4, -1, 1 }, // '_'
{ 122, 2, 1, 4, 0, -4 }, // '`'
{ 123, 3, 3, 5, 1, -3 }, // 'a'
{ 125, 3, 4, 4, 0, -4 }, // 'b'
{ 127, 3, 3, 4, 0, -3 }, // 'c'
{ 129, 3, 4, 4, 0, -4 }, // 'd'
{ 131, 3, 3, 5, 1, -3 }, // 'e'
{ 133, 3, 4, 3, -1, -4 }, // 'f'
{ 135, 3, 4, 4, 0, -3 }, // 'g'
{ 137, 3, 4, 4, 0, -4 }, // 'h'
{ 139, 1, 4, 2, 0, -4 }, // 'i'
{ 140, 2, 5, 2, -1, -4 }, // 'j'
{ 142, 3, 4, 4, 0, -4 }, // 'k'
{ 144, 1, 4, 2, 0, -4 }, // 'l'
{ 145, 5, 3, 6, 0, -3 }, // 'm'
{ 147, 3, 3, 4, 0, -3 }, // 'n'
{ 149, 3, 3, 4, 0, -3 }, // 'o'
{ 151, 3, 4, 4, 0, -3 }, // 'p'
{ 153, 3, 4, 4, 0, -3 }, // 'q'
{ 155, 2, 4, 3, 0, -4 }, // 'r'
{ 156, 3, 3, 5, 0, -3 }, // 's'
{ 158, 3, 4, 3, -1, -4 }, // 't'
{ 160, 3, 4, 4, 0, -4 }, // 'u'
{ 162, 3, 3, 4, 0, -3 }, // 'v'
{ 164, 4, 3, 5, 0, -3 }, // 'w'
{ 166, 3, 3, 4, 0, -3 }, // 'x'
{ 168, 3, 4, 4, 0, -3 }, // 'y'
{ 170, 2, 3, 5, 1, -3 }, // 'z'
{ 171, 3, 5, 4, 0, -4 }, // '{'
{ 173, 1, 6, 2, 0, -4 }, // '|'
{ 174, 3, 5, 4, 0, -4 } // '}'
};
const GFXfont Dialog_plain_5 PROGMEM = {
(uint8_t *)Dialog_plain_5Bitmaps,(GFXglyph *)Dialog_plain_5Glyphs,0x20, 0x7E, 7};