Skip to content

Commit 1ac3cf3

Browse files
committed
update printChar function and got rid of characters.h
1 parent c246921 commit 1ac3cf3

File tree

6 files changed

+96
-275
lines changed

6 files changed

+96
-275
lines changed

examples/Example1_TurnOnOneSegment/Example1_TurnOnOneSegment.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ void setup()
4040
display.illuminateSegment('L', 3);
4141
display.illuminateSegment('I', 2);
4242
display.illuminateSegment('G', 4);
43-
44-
display.updateDisplay();
4543
}
4644

4745
void loop()

examples/Example2_PrintChar/Example2_PrintChar.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ void setup()
4040
display.printChar('H', 2);
4141
display.printChar('A', 3);
4242
display.printChar('T', 4);
43-
44-
display.updateDisplay();
4543
}
4644

4745
void loop(){

examples/Example3_PrintString/Example3_PrintString.ino

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ void setup() {
3535
display.initialize();
3636
display.clearDisplay();
3737

38-
display.printString("EVEN", 4);
39-
40-
display.updateDisplay();
38+
display.printString("HAHA", 4);
4139
}
4240

4341
void loop(){

src/SparkFun_Alphanumeric_Display.cpp

Lines changed: 94 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ void HT16K33::illuminateSegment(uint8_t segment, uint8_t digit)
182182

183183
//Update displayRAM array
184184
displayRAM[adr] = displayRAM[adr] ^ dat;
185+
updateDisplay();
185186
}
186187

187188
void HT16K33::illuminateChar(uint16_t disp, uint8_t digit)
@@ -195,202 +196,103 @@ void HT16K33::illuminateChar(uint16_t disp, uint8_t digit)
195196
}
196197
}
197198

198-
void HT16K33::printChar(uint8_t dispChar, uint8_t digit)
199+
#define SFE_ALPHANUM_UNKNOWN_CHAR 75
200+
201+
void HT16K33::printChar(uint8_t displayChar, uint8_t digit)
199202
{
200-
uint16_t temp;
201-
switch (dispChar)
203+
static uint16_t alphanumeric_segs[62]{
204+
0b111111, //'0'
205+
0b10000000110, //'1'
206+
0b101011011, //'2'
207+
0b101001111, //'3'
208+
0b101100110, //'4'
209+
0b101101101, //'5'
210+
0b101111101, //'6'
211+
0b1010000000001, //'7'
212+
0b101111111, //'8'
213+
0b101100111, //'9'
214+
0b101110111, //'A'
215+
0b1001100001111, //'B'
216+
0b111001, //'C'
217+
0b1001000001111, //'D'
218+
0b101111001, //'E'
219+
0b101110001, //'F'
220+
0b100111101, //'G'
221+
0b101110110, //'H'
222+
0b1001000001001, //'I'
223+
0b11110, //'J'
224+
0b110001110000, //'K'
225+
0b111000, //'L'
226+
0b10010110110, //'M'
227+
0b100010110110, //'N'
228+
0b111111, //'O'
229+
0b101110011, //'P'
230+
0b100000111111, //'Q'
231+
0b100101110011, //'R'
232+
0b110001101, //'S'
233+
0b1001000000001, //'T'
234+
0b111110, //'U'
235+
0b10010000110000, //'V'
236+
0b10100000110110, //'W'
237+
0b10110010000000, //'X'
238+
0b1010010000000, //'Y'
239+
0b10010000001001, //'Z'
240+
0b101011111, //'a'
241+
0b100001111000, //'b'
242+
0b101011000, //'c'
243+
0b10000100001110, //'d'
244+
0b1111001, //'e'
245+
0b1110001, //'f'
246+
0b110001111, //'g'
247+
0b101110100, //'h'
248+
0b1000000000000, //'i'
249+
0b1110, //'j'
250+
0b1111000000000, //'k'
251+
0b1001000000000, //'l'
252+
0b1000101010100, //'m'
253+
0b100001010000, //'n'
254+
0b101011100, //'o'
255+
0b10001110001, //'p'
256+
0b100101100011, //'q'
257+
0b1010000, //'r'
258+
0b110001101, //'s'
259+
0b1111000, //'t'
260+
0b11100, //'u'
261+
0b10000000010000, //'v'
262+
0b10100000010100, //'w'
263+
0b10110010000000, //'x'
264+
0b1100001110, //'y'
265+
0b10010000001001, //'z'
266+
// ... 0b111001011, //Astrick / Unknown character
267+
};
268+
269+
uint16_t characterPosition = 0;
270+
271+
//Digits
272+
if (displayChar >= '0' && displayChar <= '9')
273+
{
274+
characterPosition = displayChar - '0';
275+
}
276+
//Upper case letters
277+
else if (displayChar >= 'A' && displayChar <= 'Z')
278+
{
279+
characterPosition = displayChar - 'A' + 10;
280+
}
281+
//Lower case letters
282+
else if (displayChar >= 'a' && displayChar <= 'z')
283+
{
284+
characterPosition = displayChar - 'a' + 10 + 26;
285+
}
286+
else //Symbols
202287
{
203-
case '0':
204-
temp = SEG_0;
205-
break;
206-
case '1':
207-
temp = SEG_1;
208-
break;
209-
case '2':
210-
temp = SEG_2;
211-
break;
212-
case '3':
213-
temp = SEG_3;
214-
break;
215-
case '4':
216-
temp = SEG_4;
217-
break;
218-
case '5':
219-
temp = SEG_5;
220-
break;
221-
case '6':
222-
temp = SEG_6;
223-
break;
224-
case '7':
225-
temp = SEG_7;
226-
break;
227-
case '8':
228-
temp = SEG_8;
229-
break;
230-
case '9':
231-
temp = SEG_9;
232-
break;
233-
case 'A':
234-
temp = SEG_A;
235-
break;
236-
case 'B':
237-
temp = SEG_B;
238-
break;
239-
case 'C':
240-
temp = SEG_C;
241-
break;
242-
case 'D':
243-
temp = SEG_D;
244-
break;
245-
case 'E':
246-
temp = SEG_E;
247-
break;
248-
case 'F':
249-
temp = SEG_F;
250-
break;
251-
case 'G':
252-
temp = SEG_G;
253-
break;
254-
case 'H':
255-
temp = SEG_H;
256-
break;
257-
case 'I':
258-
temp = SEG_I;
259-
break;
260-
case 'J':
261-
temp = SEG_J;
262-
break;
263-
case 'K':
264-
temp = SEG_K;
265-
break;
266-
case 'L':
267-
temp = SEG_L;
268-
break;
269-
case 'M':
270-
temp = SEG_M;
271-
break;
272-
case 'N':
273-
temp = SEG_N;
274-
break;
275-
case 'O':
276-
temp = SEG_O;
277-
break;
278-
case 'P':
279-
temp = SEG_P;
280-
break;
281-
case 'Q':
282-
temp = SEG_Q;
283-
break;
284-
case 'R':
285-
temp = SEG_R;
286-
break;
287-
case 'S':
288-
temp = SEG_S;
289-
break;
290-
case 'T':
291-
temp = SEG_T;
292-
break;
293-
case 'U':
294-
temp = SEG_U;
295-
break;
296-
case 'V':
297-
temp = SEG_V;
298-
break;
299-
case 'W':
300-
temp = SEG_W;
301-
break;
302-
case 'X':
303-
temp = SEG_X;
304-
break;
305-
case 'Y':
306-
temp = SEG_Y;
307-
break;
308-
case 'Z':
309-
temp = SEG_Z;
310-
break;
311-
case 'a':
312-
temp = SEG_a;
313-
break;
314-
case 'b':
315-
temp = SEG_b;
316-
break;
317-
case 'c':
318-
temp = SEG_c;
319-
break;
320-
case 'd':
321-
temp = SEG_d;
322-
break;
323-
case 'e':
324-
temp = SEG_e;
325-
break;
326-
case 'f':
327-
temp = SEG_f;
328-
break;
329-
case 'g':
330-
temp = SEG_g;
331-
break;
332-
case 'h':
333-
temp = SEG_h;
334-
break;
335-
case 'i':
336-
temp = SEG_i;
337-
break;
338-
case 'j':
339-
temp = SEG_j;
340-
break;
341-
case 'k':
342-
temp = SEG_k;
343-
break;
344-
case 'l':
345-
temp = SEG_l;
346-
break;
347-
case 'm':
348-
temp = SEG_m;
349-
break;
350-
case 'n':
351-
temp = SEG_n;
352-
break;
353-
case 'o':
354-
temp = SEG_o;
355-
break;
356-
case 'p':
357-
temp = SEG_p;
358-
break;
359-
case 'q':
360-
temp = SEG_q;
361-
break;
362-
case 'r':
363-
temp = SEG_r;
364-
break;
365-
case 's':
366-
temp = SEG_s;
367-
break;
368-
case 't':
369-
temp = SEG_t;
370-
break;
371-
case 'u':
372-
temp = SEG_u;
373-
break;
374-
case 'v':
375-
temp = SEG_v;
376-
break;
377-
case 'w':
378-
temp = SEG_w;
379-
break;
380-
case 'x':
381-
temp = SEG_x;
382-
break;
383-
case 'y':
384-
temp = SEG_y;
385-
break;
386-
case 'z':
387-
temp = SEG_z;
388-
break;
389-
default:
390-
temp = SEG_CLEAR;
288+
characterPosition = displayChar + (10 + 26 + 26);
391289
}
392290

393-
illuminateChar(temp, digit);
291+
//User wants to display unknown character
292+
if (characterPosition > sizeof(alphanumeric_segs))
293+
characterPosition = SFE_ALPHANUM_UNKNOWN_CHAR;
294+
295+
illuminateChar(alphanumeric_segs[characterPosition], digit);
394296
}
395297

396298
void HT16K33::printString(char *s, uint8_t n)

src/SparkFun_Alphanumeric_Display.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Distributed as-is; no warranty is given.
2222

2323
#include <Wire.h>
2424
#include <Arduino.h>
25-
#include "characters.h"
2625

2726
#define DEFAULT_ADDRESS 0x70 //Default I2C address when A0, A1 are floating
2827
#define DEV_ID 0x12 //Device ID that I just made up
@@ -47,7 +46,7 @@ class HT16K33
4746
bool clearDisplay();
4847
void illuminateSegment(uint8_t segment, uint8_t digit);
4948
void illuminateChar(uint16_t disp, uint8_t digit);
50-
void printChar(uint8_t dispChar, uint8_t digit);
49+
void printChar(uint8_t displayChar, uint8_t digit);
5150
void printString(char *s, uint8_t n);
5251
bool updateDisplay();
5352

0 commit comments

Comments
 (0)