Skip to content

Commit 7d023b3

Browse files
authored
Creates a method to change the font (#11)
1 parent 44d9180 commit 7d023b3

File tree

10 files changed

+1191
-11
lines changed

10 files changed

+1191
-11
lines changed

examples/Nokia_LCD_Font/LICENSE

Lines changed: 504 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include <Nokia_LCD.h>
2+
#include "fonts/Small_LCD_Fonts.h"
3+
#include "fonts/Bold_LCD_Fonts.h"
4+
#include "fonts/Glyphs_LCD_Fonts.h"
5+
6+
Nokia_LCD lcd(13 /* CLK */, 12 /* DIN */, 11 /* DC */, 10 /* CE */, 9 /* RST */, 9 /* BL */);
7+
/**
8+
* Or, if you would like to control the backlight on your own, init the lcd without the last argument
9+
* Nokia_LCD lcd(13, 12, 11, 10, 9);
10+
*/
11+
12+
/**
13+
* To change the font, create an object that represents it.
14+
* Do it in the main file or in the header font files like SmallFont and GlyphFont.
15+
**/
16+
const LcdFont BoldFont {
17+
[](char c) { return Bold_LCD_Fonts::kFont_Table[c - 0x20]; }, // method to retrieve the character
18+
Bold_LCD_Fonts::kColumns_per_character, // width of each char
19+
Bold_LCD_Fonts::hSpace, // horizontal spacing array
20+
1 // size of horizontal spacing array
21+
};
22+
23+
24+
const unsigned char TOOLBAR[] = {
25+
0x0E, // musical note
26+
0x0F, // solar
27+
0x1D, // key
28+
0xF9, // hourglass
29+
0x20, // space
30+
0x1A, // rewind
31+
0x20, // space
32+
0x1B, // pause
33+
0x20, // space
34+
0x19, // fast foward
35+
0x20, // space
36+
0x01, // battery
37+
0x02, // battery
38+
0x03 // battery
39+
};
40+
41+
void setup() {
42+
// Initialize the screen
43+
lcd.begin();
44+
// Turn on the backlight
45+
lcd.setBacklight(true);
46+
// Set the contrast
47+
lcd.setContrast(60); // Good values are usualy between 40 and 60
48+
// Clear the screen by filling it with black pixels
49+
lcd.clear();
50+
51+
52+
// Glyph font example
53+
lcd.setFont(&Glyphs_LCD_Fonts::GlyphFont);
54+
// Draw the toolbar
55+
for (int i=0; i<14; i++) {
56+
lcd.print((char) TOOLBAR[i]);
57+
}
58+
// Draw the pattern
59+
lcd.setCursor(0, 1);
60+
for (int i=0; i<14; i++) {
61+
lcd.print((char) (0xD4+(int)i/5));
62+
}
63+
64+
// Small font example
65+
lcd.setCursor(0, 2);
66+
lcd.setFont(&Small_LCD_Fonts::SmallFont);
67+
lcd.print("This is an example\nof small font, it\nuses 3px width");
68+
69+
// Bold font example
70+
lcd.setCursor(0, 5);
71+
lcd.setFont(&BoldFont);
72+
lcd.print("I'M BOLD!");
73+
}
74+
75+
void loop() {
76+
// put your main code here, to run repeatedly
77+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#pragma once
2+
// If we are not building for AVR architectures ignore PROGMEM
3+
#if defined(__AVR__)
4+
#include <avr/pgmspace.h>
5+
#else
6+
#define PROGMEM
7+
#endif
8+
9+
#include <LCD_Fonts.h>
10+
11+
/**
12+
* This example uses a font originally created by the author here:
13+
* https://github.com/gavinlyonsrepo/NOKIA5110_TEXT
14+
**/
15+
16+
namespace Bold_LCD_Fonts {
17+
const uint8_t kColumns_per_character = 7;
18+
const unsigned char hSpace[] = {0x00};
19+
const unsigned char hSpaceSize = 1;
20+
21+
22+
const unsigned char kFont_Table[][kColumns_per_character] PROGMEM = {
23+
{0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //
24+
{0x5f,0x5f,0x00,0x00,0x00,0x00,0x00}, // !
25+
{0x07,0x07,0x00,0x07,0x07,0x00,0x00}, // "
26+
{0x14,0x7f,0x7f,0x14,0x7f,0x7f,0x14}, // #
27+
{0x6f,0x6f,0x6b,0xeb,0x6b,0x7b,0x7b}, // $
28+
{0x63,0x73,0x38,0x1c,0x0e,0x67,0x63}, // %
29+
{0x7f,0x7f,0x6b,0x63,0x68,0x78,0x78}, // &
30+
{0x07,0x07,0x00,0x00,0x00,0x00,0x00}, // '
31+
{0xff,0xff,0x80,0x00,0x00,0x00,0x00}, // (
32+
{0x80,0xff,0xff,0x00,0x00,0x00,0x00}, // )
33+
{0x36,0x08,0x7f,0x7f,0x7f,0x08,0x36}, // *
34+
{0x08,0x08,0x3e,0x08,0x08,0x00,0x00}, // +
35+
{0xe0,0xe0,0x00,0x00,0x00,0x00,0x00}, // ,
36+
{0x08,0x08,0x08,0x08,0x08,0x00,0x00}, // -
37+
{0x60,0x60,0x00,0x00,0x00,0x00,0x00}, // .
38+
{0x70,0x1c,0x07,0x00,0x00,0x00,0x00}, // /
39+
{0x7f,0x7f,0x63,0x63,0x63,0x7f,0x7f}, // 0
40+
{0x60,0x66,0x66,0x7f,0x7f,0x60,0x60}, // 1
41+
{0x7b,0x7b,0x6b,0x6b,0x6b,0x6f,0x6f}, // 2
42+
{0x63,0x63,0x6b,0x6b,0x6b,0x7f,0x7f}, // 3
43+
{0x1f,0x1f,0x18,0x18,0x18,0x7e,0x7e}, // 4
44+
{0x6f,0x6f,0x6b,0x6b,0x6b,0x7b,0x7b}, // 5
45+
{0x7f,0x7f,0x6c,0x6c,0x6c,0x7c,0x7c}, // 6
46+
{0x43,0x63,0x73,0x3b,0x1f,0x0f,0x07}, // 7
47+
{0x7f,0x7f,0x6b,0x6b,0x6b,0x7f,0x7f}, // 8
48+
{0x1f,0x1f,0x1b,0x1b,0x1b,0x7f,0x7f}, // 9
49+
{0x6c,0x6c,0x00,0x00,0x00,0x00,0x00}, // :
50+
{0xec,0xec,0x00,0x00,0x00,0x00,0x00}, // ;
51+
{0x08,0x14,0x22,0x22,0x00,0x00,0x00}, // <
52+
{0x14,0x14,0x14,0x14,0x14,0x00,0x00}, // =
53+
{0x22,0x22,0x14,0x08,0x00,0x00,0x00}, // >
54+
{0x03,0x03,0x5b,0x5b,0x0b,0x0f,0x0f}, // ?
55+
{0x7f,0x7f,0x63,0x6f,0x6b,0x6f,0x6f}, // @
56+
{0x7f,0x7f,0x1b,0x1b,0x1b,0x7f,0x7f}, // A
57+
{0x7f,0x7f,0x6b,0x6b,0x6f,0x7e,0x7c}, // B
58+
{0x7f,0x7f,0x63,0x63,0x63,0x63,0x63}, // C
59+
{0x7f,0x7f,0x63,0x63,0x67,0x7e,0x7c}, // D
60+
{0x7f,0x7f,0x6b,0x6b,0x6b,0x6b,0x6b}, // E
61+
{0x7f,0x7f,0x0b,0x0b,0x0b,0x03,0x03}, // F
62+
{0x7f,0x7f,0x63,0x63,0x6b,0x7b,0x7b}, // G
63+
{0x7f,0x7f,0x18,0x18,0x18,0x7f,0x7f}, // H
64+
{0x63,0x63,0x7f,0x7f,0x63,0x63,0x63}, // I
65+
{0x60,0x60,0x60,0x60,0x60,0x7f,0x3f}, // J
66+
{0x7f,0x7f,0x18,0x18,0x1e,0x7f,0x79}, // K
67+
{0x7f,0x7f,0x60,0x60,0x60,0x60,0x60}, // L
68+
{0x7f,0x7f,0x03,0x06,0x03,0x7f,0x7f}, // M
69+
{0x7f,0x7f,0x0e,0x1c,0x38,0x7f,0x7f}, // N
70+
{0x7f,0x7f,0x63,0x63,0x63,0x7f,0x7f}, // O
71+
{0x7f,0x7f,0x1b,0x1b,0x1b,0x1f,0x1f}, // P
72+
{0x7f,0x7f,0x63,0xf3,0xf3,0x7f,0x7f}, // Q
73+
{0x7f,0x7f,0x1b,0x3b,0x7b,0x7f,0x5f}, // R
74+
{0x6f,0x6f,0x6b,0x6b,0x6b,0x7b,0x7b}, // S
75+
{0x03,0x03,0x7f,0x7f,0x03,0x03,0x03}, // T
76+
{0x7f,0x7f,0x60,0x60,0x60,0x7f,0x7f}, // U
77+
{0x1f,0x3f,0x70,0x60,0x70,0x3f,0x1f}, // V
78+
{0x3f,0x7f,0x60,0x30,0x60,0x7f,0x3f}, // W
79+
{0x77,0x7f,0x1c,0x08,0x1c,0x7f,0x77}, // X
80+
{0x07,0x0f,0x7c,0x78,0x7c,0x0f,0x07}, // Y
81+
{0x73,0x7b,0x6b,0x6b,0x6b,0x6f,0x67}, // Z
82+
};
83+
84+
} // namespace Nokia_LCD_Fonts

0 commit comments

Comments
 (0)