AceSegment
0.7.0
A framework for rendering seven segment LED displays using the TM1637, MAX7219, HT16K33, or 74HC595 controller chips
src
ace_segment
writer
CharWriter.cpp
1
/*
2
MIT License
3
4
Copyright (c) 2018 Brian T. Park
5
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in all
14
copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
SOFTWARE.
23
*/
24
25
#include <Arduino.h>
26
#include "CharWriter.h"
27
28
namespace
ace_segment {
29
30
// A poor-man's '?': 0b10000011
31
//static const uint8_t UNKNOWN = 0b10000011;
32
33
// Set unknown character to be blank. The problem with '?' is that some LED
34
// modules don't have an active decimal point on all digits, so the '?' does not
35
// look right.
36
static
const
uint8_t UNKNOWN = 0b00000000;
37
38
// Bit patterns for ASCII characters (0 - 127).
39
// Adapted from https://github.com/dmadison/LED-Segment-ASCII.
40
//
41
// 7-segment map:
42
// AAA 000
43
// F B 5 1
44
// F B 5 1
45
// GGG 666
46
// E C 4 2
47
// E C 4 2
48
// DDD DP 333 77
49
//
50
// Segment: DP G F E D C B A
51
// Bits: 7 6 5 4 3 2 1 0
52
//
53
const
uint8_t CharWriter::kCharPatterns[] PROGMEM = {
54
UNKNOWN,
/* 00 */
55
UNKNOWN,
/* 01 */
56
UNKNOWN,
/* 02 */
57
UNKNOWN,
/* 03 */
58
UNKNOWN,
/* 04 */
59
UNKNOWN,
/* 05 */
60
UNKNOWN,
/* 06 */
61
UNKNOWN,
/* 07 */
62
UNKNOWN,
/* 08 */
63
UNKNOWN,
/* 09 */
64
UNKNOWN,
/* 10 */
65
UNKNOWN,
/* 11 */
66
UNKNOWN,
/* 12 */
67
UNKNOWN,
/* 13 */
68
UNKNOWN,
/* 14 */
69
UNKNOWN,
/* 15 */
70
UNKNOWN,
/* 16 */
71
UNKNOWN,
/* 17 */
72
UNKNOWN,
/* 18 */
73
UNKNOWN,
/* 19 */
74
UNKNOWN,
/* 20 */
75
UNKNOWN,
/* 21 */
76
UNKNOWN,
/* 22 */
77
UNKNOWN,
/* 23 */
78
UNKNOWN,
/* 24 */
79
UNKNOWN,
/* 25 */
80
UNKNOWN,
/* 26 */
81
UNKNOWN,
/* 27 */
82
UNKNOWN,
/* 28 */
83
UNKNOWN,
/* 29 */
84
UNKNOWN,
/* 30 */
85
UNKNOWN,
/* 31 */
86
0b00000000,
/* (space) */
87
0b10000110,
/* ! */
88
0b00100010,
/* " */
89
0b01111110,
/* # */
90
0b01101101,
/* $ */
91
0b11010010,
/* % */
92
0b01000110,
/* & */
93
0b00100000,
/* ' */
94
0b00101001,
/* ( */
95
0b00001011,
/* ) */
96
0b00100001,
/* * */
97
0b01110000,
/* + */
98
0b00010000,
/* , */
99
0b01000000,
/* - */
100
0b10000000,
/* . */
101
0b01010010,
/* / */
102
0b00111111,
/* 0 */
103
0b00000110,
/* 1 */
104
0b01011011,
/* 2 */
105
0b01001111,
/* 3 */
106
0b01100110,
/* 4 */
107
0b01101101,
/* 5 */
108
0b01111101,
/* 6 */
109
0b00000111,
/* 7 */
110
0b01111111,
/* 8 */
111
0b01101111,
/* 9 */
112
0b00001001,
/* : */
113
0b00001101,
/* ; */
114
0b01100001,
/* < */
115
0b01001000,
/* = */
116
0b01000011,
/* > */
117
0b11010011,
/* ? */
118
0b01011111,
/* @ */
119
0b01110111,
/* A */
120
0b01111100,
/* B */
121
0b00111001,
/* C */
122
0b01011110,
/* D */
123
0b01111001,
/* E */
124
0b01110001,
/* F */
125
0b00111101,
/* G */
126
0b01110110,
/* H */
127
0b00110000,
/* I */
128
0b00011110,
/* J */
129
0b01110101,
/* K */
130
0b00111000,
/* L */
131
0b00010101,
/* M */
132
0b00110111,
/* N */
133
0b00111111,
/* O */
134
0b01110011,
/* P */
135
0b01101011,
/* Q */
136
0b00110011,
/* R */
137
0b01101101,
/* S */
138
0b01111000,
/* T */
139
0b00111110,
/* U */
140
0b00111110,
/* V */
141
0b00101010,
/* W */
142
0b01110110,
/* X */
143
0b01101110,
/* Y */
144
0b01011011,
/* Z */
145
0b00111001,
/* [ */
146
0b01100100,
/* \ */
147
0b00001111,
/* ] */
148
0b00100011,
/* ^ */
149
0b00001000,
/* _ */
150
0b00000010,
/* ` */
151
0b01011111,
/* a */
152
0b01111100,
/* b */
153
0b01011000,
/* c */
154
0b01011110,
/* d */
155
0b01111011,
/* e */
156
0b01110001,
/* f */
157
0b01101111,
/* g */
158
0b01110100,
/* h */
159
0b00010000,
/* i */
160
0b00001100,
/* j */
161
0b01110101,
/* k */
162
0b00110000,
/* l */
163
0b00010100,
/* m */
164
0b01010100,
/* n */
165
0b01011100,
/* o */
166
0b01110011,
/* p */
167
0b01100111,
/* q */
168
0b01010000,
/* r */
169
0b01101101,
/* s */
170
0b01111000,
/* t */
171
0b00011100,
/* u */
172
0b00011100,
/* v */
173
0b00010100,
/* w */
174
0b01110110,
/* x */
175
0b01101110,
/* y */
176
0b01011011,
/* z */
177
0b01000110,
/* { */
178
0b00110000,
/* | */
179
0b01110000,
/* } */
180
0b00000001,
/* ~ */
181
UNKNOWN,
/* (del) */
182
};
183
184
uint8_t
CharWriter::getPattern
(
char
c)
const
{
185
uint8_t pattern = ((mNumChars == 0) || ((uint8_t) c < mNumChars))
186
? pgm_read_byte(&mCharPatterns[(uint8_t) c])
187
: UNKNOWN;
188
return
pattern;
189
}
190
191
void
CharWriter::writeCharAt
(uint8_t pos,
char
c) {
192
if
(pos >= mPatternWriter.
getNumDigits
())
return
;
193
mPatternWriter.
writePatternAt
(pos,
getPattern
(c));
194
}
195
196
}
ace_segment::PatternWriter::writePatternAt
void writePatternAt(uint8_t pos, uint8_t pattern)
Write the pattern for a given pos.
Definition:
PatternWriter.h:61
ace_segment::CharWriter::writeCharAt
void writeCharAt(uint8_t pos, char c)
Write the character at the specified position.
Definition:
CharWriter.cpp:191
ace_segment::CharWriter::getPattern
uint8_t getPattern(char c) const
Get segment pattern for character 'c'.
Definition:
CharWriter.cpp:184
ace_segment::PatternWriter::getNumDigits
uint8_t getNumDigits() const
Return the number of digits supported by this display instance.
Definition:
PatternWriter.h:55
Generated by
1.8.17