This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
fonts.h
147 lines (141 loc) · 6.02 KB
/
fonts.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#ifndef FONTS_H
#define FONTS_H
//currently PROGMEM in class members doesnt work on ESP8266
#ifdef ESP8266
#define PROG_MEM
#else
#define PROG_MEM PROGMEM
#endif
class font5x3
{
private:
byte fontwidth = 3;
byte fontheight = 5;
const bool n1[15] PROG_MEM = {0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1};
const bool n2[15] PROG_MEM = {1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1};
const bool n3[15] PROG_MEM = {1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1};
const bool n4[15] PROG_MEM = {0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1};
const bool n5[15] PROG_MEM = {1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1};
const bool n6[15] PROG_MEM = {1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1};
const bool n7[15] PROG_MEM = {0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1};
const bool n8[15] PROG_MEM = {1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1};
const bool n9[15] PROG_MEM = {1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1};
const bool n0[15] PROG_MEM = {1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1};
const bool nc[15] PROG_MEM = {1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0};
public:
font5x3() {}
~font5x3() {}
//This Method gets as input an string of numbers (s) and a starting position s_x and s_y. c1 is the foreground color and c2 the background color.
//The Method then goes through the input string and chooses the right array containing boolean pixeldata (1 = foreground color, 0 = background color)
void drawNumber(Matrix &matrix, byte s_x, byte s_y, String s, CRGB c1 = CRGB::White, CRGB c2 = CRGB::Black) //Draw a Number at x,y
{
bool * numberTemp; //temporary non const pointer to store the right address
for (byte i = 0; i < s.length(); i++) //go through the input string s f.e. "10"
{
byte x = s_x + (fontwidth + 1) * i; //x,y drawing position for the current number
byte y = s_y;
switch (s[i]) //chose the right array for the current nuber
{
case '1': numberTemp = (bool*)n1;
break;
case '2': numberTemp = (bool*)n2;
break;
case '3': numberTemp = (bool*)n3;
break;
case '4': numberTemp = (bool*)n4;
break;
case '5': numberTemp = (bool*)n5;
break;
case '6': numberTemp = (bool*)n6;
break;
case '7': numberTemp = (bool*)n7;
break;
case '8': numberTemp = (bool*)n8;
break;
case '9': numberTemp = (bool*)n9;
break;
case 'c': numberTemp = (bool*)nc;
break;
default: numberTemp = (bool*)n0;
break;
}
const bool* number = numberTemp; //make it const again
for (byte column = 1, counter = 0; column <= fontheight; column++) //Set the right pixels in the led matrix based on the array chosen above.
{
for (byte row = 1; row <= fontwidth; row++, counter++)
{
if (number[counter] == true)
matrix.setPixel(x + row - 1, y + column - 1, c1);
else
matrix.setPixel(x + row - 1, y + column - 1, c2);
}
}
}
}
};
class font7x3
{
private:
byte fontwidth = 3;
byte fontheight = 7;
const bool n1[21] PROG_MEM = {0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1};
const bool n2[21] PROG_MEM = {1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1};
const bool n3[21] PROG_MEM = {1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1};
const bool n4[21] PROG_MEM = {0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1};
const bool n5[21] PROG_MEM = {1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1};
const bool n6[21] PROG_MEM = {1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1};
const bool n7[21] PROG_MEM = {0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1};
const bool n8[21] PROG_MEM = {1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1};
const bool n9[21] PROG_MEM = {1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1};
const bool n0[21] PROG_MEM = {1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1};
const bool nc[21] PROG_MEM = {1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0};
public:
font7x3() {}
~font7x3() {}
void drawNumber(Matrix &matrix, byte s_x, byte s_y, String s, CRGB c1 = CRGB::White, CRGB c2 = CRGB::Black) //Draw a Number at x,y
{
bool * numberTemp; //temporary non const pointer to store the right address
for (byte i = 0; i < s.length(); i++) //go through the input string s f.e. "10"
{
byte x = s_x + (fontwidth + 1) * i; //x,y drawing position for the current number
byte y = s_y;
switch (s[i]) //chose the right array for the current nuber
{
case '1': numberTemp = (bool*)n1;
break;
case '2': numberTemp = (bool*)n2;
break;
case '3': numberTemp = (bool*)n3;
break;
case '4': numberTemp = (bool*)n4;
break;
case '5': numberTemp = (bool*)n5;
break;
case '6': numberTemp = (bool*)n6;
break;
case '7': numberTemp = (bool*)n7;
break;
case '8': numberTemp = (bool*)n8;
break;
case '9': numberTemp = (bool*)n9;
break;
case 'c': numberTemp = (bool*)nc;
break;
default: numberTemp = (bool*)n0;
break;
}
const bool* number = numberTemp; //make it const again
for (byte column = 1, counter = 0; column <= fontheight; column++) //Set the right pixels in the led matrix based on the array chosen above.
{
for (byte row = 1; row <= fontwidth; row++, counter++)
{
if (number[counter] == true)
matrix.setPixel(x + row - 1, y + column - 1, c1);
else
matrix.setPixel(x + row - 1, y + column - 1, c2);
}
}
}
}
};
#endif //fonts_matrix_h