-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHT1632.cpp
More file actions
749 lines (649 loc) · 22.4 KB
/
HT1632.cpp
File metadata and controls
749 lines (649 loc) · 22.4 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
/*
*********************************************************************************************************
* HT1632.cpp
*
* Apr/10 by FlorinC (http://timewitharduino.blogspot.com/)
* Copyrighted and distributed under the terms of the Berkeley license
* (copy freely, but include this notice of original authors.)
*
* Adapted after HT1632 library by Bill Westfield ("WestfW") (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1225239439/0);
*
* Other contributors:
* - fWrite (fast writes) functions courtesy of BroHogan (http://brohogan.blogspot.com/);
* - Mark Sproul <MLS> msproul _at_ jove.rutgers.edu
*
*********************************************************************************************************
*/
//*********************************************************************************************************
//* Edit History, started April, 2010
//* please put your initials and comments here anytime you make changes
//*********************************************************************************************************
//* Apr 15/10 (fc) created file, by restructuring Wise4Sure.pde;
//* Oct 10/10 (rp) ht1632_putBigDigit() amended to allow for multiple fonts
//* Jan 29/11 (fc) adapted to 3216 bi-color display;
//* Jun 12/11 (rp) ht1632_putchar(), ht1632_putSmallChar() amended for ascii character 127 (degree symbol)
//* Jun 12/11 (rp) ht1632_putBigDigit() now has color and columns parameter;
//* Jun 20/11 (fc) added ht1632_putBitmap(), ht1632_putTinyChar(), setBrightness();
//* Oct 15/11 (rp) added overlayWithSnapshotHorizontal(), overlayWithSnapshotVertical(), ht1632_putLargeChar();
//* added PUTINSNAPSHOTRAM option plus several small speed optimalizations;
//*
//*********************************************************************************************************
#include "HT1632.h"
#include <avr/pgmspace.h> // fonts are now loaded in program space;
#include "font3.h"
#include "fontBig.h"
#include "fontSmall.h"
#include "fontTiny.h"
#include "bitmaps2.h"
#ifdef _FONTLARGE_
#include "fontLarge.h"
#endif
#define CHIP_MAX 4 //Four HT1632Cs on one board
#define CLK_DELAY
// QVS March 2012 support our pinout..
#define HT1632_DATA 6 // Data pin (pin 7 of display connector)
#define HT1632_CS 5 // Chip Select (pin 1 of display connnector)
#define HT1632_WRCLK 4 // Write clock pin (pin 5 of display connector)
#define HT1632_CLK 3 // clock pin (pin 2 of display connector)
// QVS March 2012 add support for ATMega328
#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) // compiled as ATMega644
//Atmega644 Version of fastWrite - for pins 0-15
#define fWriteA(_pin_, _state_) ( _pin_ < 8 ? (_state_ ? PORTB |= 1 << _pin_ : \
PORTB &= ~(1 << _pin_ )) : (_state_ ? PORTD |= 1 << (_pin_ -8) : PORTD &= ~(1 << (_pin_ -8) )))
//Atmega644 Version of fastWrite - for pins 16-31 (Note: PORTA mapping reversed from others)
#define fWriteB(_pin_, _state_) ( _pin_ < 24 ? (_state_ ? PORTC |= 1 << (_pin_ -16) : \
PORTC &= ~(1 << (_pin_ -16))) : (_state_ ? PORTA |= 1 << (31- _pin_) : PORTA &= ~(1 << (31- _pin_) )))
#else // if ATMega328
//Atmega328 Version of fastWrite - for pins 0-13
#define fWriteA(_pin_, _state_) ( _pin_ < 8 ? (_state_ ? PORTD |= 1 << _pin_ : \
PORTD &= ~(1 << _pin_ )) : (_state_ ? PORTB |= 1 << (_pin_ -8) : PORTB &= ~(1 << (_pin_ -8) )))
//Atmega328 Version of fastWrite - for pins 14-19
#define fWriteB(_pin, _state_) (_state_ ? PORTC |= 1 << (_pin - 14) : \
PORTC &= ~(1 << (_pin -14) ))
#endif
//*********************************************************************************************************
// our own copy of the "video" memory; 64 bytes for each of the 4 screen quarters;
// each 64-element array maps 2 planes:
// indexes from 0 to 31 are allocated for green plane;
// indexes from 32 to 63 are allocated for red plane;
// when a bit is 1 in both planes, it is displayed as orange (green + red);
byte ht1632_shadowram[64][4] = {0};
//**************************************************************************************************
//Function Name: OutputCLK_Pulse
//Function Feature: enable CLK_74164 pin to output a clock pulse
//Input Argument: void
//Output Argument: void
//**************************************************************************************************
void OutputCLK_Pulse(void) //Output a clock pulse
{
fWriteA(HT1632_CLK, HIGH);
// digitalWrite(HT1632_CLK, HIGH);
fWriteA(HT1632_CLK, LOW);
// digitalWrite(HT1632_CLK, LOW);
}
//**************************************************************************************************
//Function Name: OutputA_74164
//Function Feature: enable pin A of 74164 to output 0 or 1
//Input Argument: x: if x=1, 74164 outputs high. If x?1, 74164 outputs low.
//Output Argument: void
//**************************************************************************************************
void OutputA_74164(unsigned char x) //Input a digital level to 74164
{
fWriteA(HT1632_CS, (x==1 ? HIGH : LOW));
// digitalWrite(HT1632_CS, (x==1 ? HIGH : LOW));
}
//**************************************************************************************************
//Function Name: ChipSelect
//Function Feature: enable HT1632C
//Input Argument: select: HT1632C to be selected
// If select=0, select none.
// If s<0, select all.
//Output Argument: void
//**************************************************************************************************
void ChipSelect(int select)
{
unsigned char tmp = 0;
if(select<0) //Enable all HT1632Cs
{
OutputA_74164(0);
CLK_DELAY;
for(tmp=0; tmp<CHIP_MAX; tmp++)
{
OutputCLK_Pulse();
}
}
else if(select==0) //Disable all HT1632Cs
{
OutputA_74164(1);
CLK_DELAY;
for(tmp=0; tmp<CHIP_MAX; tmp++)
{
OutputCLK_Pulse();
}
}
else
{
OutputA_74164(1);
CLK_DELAY;
for(tmp=0; tmp<CHIP_MAX; tmp++)
{
OutputCLK_Pulse();
}
OutputA_74164(0);
CLK_DELAY;
OutputCLK_Pulse();
CLK_DELAY;
OutputA_74164(1);
CLK_DELAY;
tmp = 1;
for( ; tmp<select; tmp++)
{
OutputCLK_Pulse();
}
}
}
//*********************************************************************************************************
void ht1632_setup()
{
pinMode(HT1632_CS, OUTPUT);
digitalWrite(HT1632_CS, HIGH); /* unselect (active low) */
pinMode(HT1632_WRCLK, OUTPUT);
pinMode(HT1632_DATA, OUTPUT);
pinMode(HT1632_CLK, OUTPUT);
for (int j=1; j<5; j++)
{
ht1632_sendcmd(j, HT1632_CMD_SYSDIS); // Disable system
ht1632_sendcmd(j, HT1632_CMD_COMS00);
ht1632_sendcmd(j, HT1632_CMD_MSTMD); /* Master Mode */
ht1632_sendcmd(j, HT1632_CMD_RCCLK); // HT1632C
ht1632_sendcmd(j, HT1632_CMD_SYSON); /* System on */
ht1632_sendcmd(j, HT1632_CMD_LEDON); /* LEDs on */
}
ht1632_clear();
delay(100);
}
//*********************************************************************************************************
/*
* plot a point on the display, with the upper left hand corner
* being (0,0), and the lower right hand corner being (31, 15);
* parameter "color" could have one of the 4 values:
* black (off), red, green or yellow;
*/
void ht1632_plot (int x, int y, byte color)
{
if (x<0 || x>=X_MAX || y<0 || y>=Y_MAX)
return;
if (color & PUTINSNAPSHOTRAM)
{
put_snapshotram(x, y, color & ORANGE);
return;
}
// if (color != BLACK && color != GREEN && color != RED && color != ORANGE)
if (color > ORANGE)
return;
// if (color == get_shadowram(x, y))
// return; // nothing to change;
byte nChip = x / 16 + (y > 7 ? 2 : 0) ;
y = y % 8;
byte addr = ((x % 16) << 1) + (y >> 2);
byte bitval = 8 >> (y & 3); // compute which bit will need set;
byte val = (ht1632_shadowram[addr][nChip] & bitval) ? 1 : 0;
val += (ht1632_shadowram[addr+32][nChip] & bitval) ? 2 : 0;
if (color == val)
return; // nothing to change;
switch (color)
{
case BLACK:
// clear the bit in both planes;
ht1632_shadowram[addr][nChip] &= ~bitval;
ht1632_senddata(nChip+1, addr, ht1632_shadowram[addr][nChip]);
addr = addr + 32;
ht1632_shadowram[addr][nChip] &= ~bitval;
ht1632_senddata(nChip+1, addr, ht1632_shadowram[addr][nChip]);
break;
case GREEN:
// set the bit in the green plane and clear the bit in the red plane;
ht1632_shadowram[addr][nChip] |= bitval;
ht1632_senddata(nChip+1, addr, ht1632_shadowram[addr][nChip]);
addr = addr + 32;
ht1632_shadowram[addr][nChip] &= ~bitval;
ht1632_senddata(nChip+1, addr, ht1632_shadowram[addr][nChip]);
break;
case RED:
// clear the bit in green plane and set the bit in the red plane;
ht1632_shadowram[addr][nChip] &= ~bitval;
ht1632_senddata(nChip+1, addr, ht1632_shadowram[addr][nChip]);
addr = addr + 32;
ht1632_shadowram[addr][nChip] |= bitval;
ht1632_senddata(nChip+1, addr, ht1632_shadowram[addr][nChip]);
break;
case ORANGE:
// set the bit in both the green and red planes;
ht1632_shadowram[addr][nChip] |= bitval;
ht1632_senddata(nChip+1, addr, ht1632_shadowram[addr][nChip]);
addr = addr + 32;
ht1632_shadowram[addr][nChip] |= bitval;
ht1632_senddata(nChip+1, addr, ht1632_shadowram[addr][nChip]);
break;
}
}
//*********************************************************************************************************
/*
* ht1632_clear
* clear the display, and the shadow memory, and the snapshot
* memory. This uses the "write multiple words" capability of
* the chipset by writing all 96 words of memory without raising
* the chipselect signal.
*/
void ht1632_clear()
{
memset(ht1632_shadowram, 0,sizeof(ht1632_shadowram));
// clear our own shadow memory;
/*
for (int i=0; i < 4; i++)
{
for (int j=0; j < 64; j++)
ht1632_shadowram[j][i] = 0;
}
*/
// clear the display memory;
for (byte i=0; i<96; i++)
{
ht1632_senddata(1, i, 0); // clear the display!
ht1632_senddata(2, i, 0); // clear the display!
ht1632_senddata(3, i, 0); // clear the display!
ht1632_senddata(4, i, 0); // clear the display!
}
}
//*********************************************************************************************************
/*
* snapshot_shadowram
* Copy the shadow ram into the snapshot ram (the upper bits)
* This gives us a separate copy so we can plot new data while
* still having a copy of the old data. snapshotram is NOT
* updated by the plot functions (except "clear").
*/
void snapshot_shadowram()
{
for (int nQuarter=0; nQuarter<4; nQuarter++)
{
for (byte i=0; i<64; i++)
{
// copy the video bits (lower 4) in the upper 4;
byte val = ht1632_shadowram[i][nQuarter];
ht1632_shadowram[i][nQuarter] = (val & 0x0F) + (val << 4);
}
}
}
//*********************************************************************************************************
/*
* return the value of a pixel from the video memory (either BLACK, RED, GREEN, ORANGE);
*/
byte get_shadowram(byte x, byte y)
{
return get_videoram(x, y, 0x08); // get lower 4 bit;
}
//*********************************************************************************************************
/*
* get_snapshotram
* get a pixel value from the snapshot ram instead of the actual video memory;
* return BLACK, GREEN, RED or ORANGE;
*/
byte get_snapshotram(byte x, byte y)
{
return get_videoram(x, y, 0x80); // get higher 4 bit;
}
//*********************************************************************************************************
/*
* return the value of a pixel from the video memory (either BLACK, RED, GREEN, ORANGE);
*/
byte get_videoram(byte x, byte y, byte whichBit)
{
byte nQuarter = x / 16 + (y > 7 ? 2 : 0);
y = y % 8;
byte addr = ((x % 16) << 1) + (y >> 2);
byte bitval = whichBit >> (y & 3);
byte val = (ht1632_shadowram[addr][nQuarter] & bitval) ? 1 : 0;
val += (ht1632_shadowram[addr+32][nQuarter] & bitval) ? 2 : 0;
return val;
}
//*********************************************************************************************************
/*
* write the value of a pixel in the snapshot memory (either BLACK, RED, GREEN, ORANGE);
*/
void put_snapshotram(byte x, byte y, byte color)
{
byte nChip = x / 16 + (y > 7 ? 2 : 0);
y = y % 8;
byte addr = ((x % 16) << 1) + (y >> 2);
byte bitval = 0x80 >> (y & 3);
switch (color)
{
case BLACK:
// clear the bit in both planes;
ht1632_shadowram[addr][nChip] &= ~bitval;
ht1632_shadowram[addr+32][nChip] &= ~bitval;
break;
case GREEN:
// set the bit in the green plane and clear the bit in the red plane;
ht1632_shadowram[addr][nChip] |= bitval;
ht1632_shadowram[addr+32][nChip] &= ~bitval;
break;
case RED:
// clear the bit in green plane and set the bit in the red plane;
ht1632_shadowram[addr][nChip] &= ~bitval;
ht1632_shadowram[addr+32][nChip] |= bitval;
break;
case ORANGE:
// set the bit in both the green and red planes;
ht1632_shadowram[addr][nChip] |= bitval;
ht1632_shadowram[addr+32][nChip] |= bitval;
break;
}
}
//*********************************************************************************************************
/*
* overlay the current display with the snapshot memory line by line from top to bottom;
*/
void overlayWithSnapshotHorizontal(boolean clearSnapshotRam, int msec)
{
for (byte y = 0; y < 16; ++y)
{
for (byte x = 0; x < 32; ++x)
ht1632_plot(x, y, get_videoram(x, y, 0x80));
delay(msec);
}
if (clearSnapshotRam == true)
{
for (int i=0; i < 4; i++)
{
for (int j=0; j < 64; j++)
ht1632_shadowram[j][i] &= 0x0F;
}
}
}
//*********************************************************************************************************
/*
* overlay the current display with the snapshot memory column by column from left to right;
*/
void overlayWithSnapshotVertical(boolean clearSnapshotRam, int msec)
{
for (byte x = 0; x < 32; ++x)
{
for (byte y = 0; y < 16; ++y)
ht1632_plot(x, y, get_videoram(x, y, 0x80));
delay(msec);
}
if (clearSnapshotRam == true)
{
for (int i=0; i < 4; i++)
{
for (int j=0; j < 64; j++)
ht1632_shadowram[j][i] &= 0x0F;
}
}
}
//*********************************************************************************************************
/*
* ht1632_writebits
* Write bits (up to 8) to h1632 on pins ht1632_data, ht1632_wrclk
* Chip is assumed to already be chip-selected
* Bits are shifted out from MSB to LSB, with the first bit sent
* being (bits & firstbit), shifted till firsbit is zero.
*/
void ht1632_writebits (byte bits, byte firstbit)
{
while (firstbit)
{
fWriteA(HT1632_WRCLK, LOW); // digitalWrite(HT1632_WRCLK, LOW);
if (bits & firstbit)
{
fWriteA(HT1632_DATA, HIGH); // digitalWrite(HT1632_DATA, HIGH);
}
else
{
fWriteA(HT1632_DATA, LOW); // digitalWrite(HT1632_DATA, LOW);
}
fWriteA(HT1632_WRCLK, HIGH); // digitalWrite(HT1632_WRCLK, HIGH);
firstbit >>= 1;
}
}
//*********************************************************************************************************
/*
* ht1632_sendcmd
* Send a command to the ht1632 chip.
*/
void ht1632_sendcmd (byte chipNo, byte command)
{
ChipSelect(chipNo);
ht1632_writebits(HT1632_ID_CMD, 1<<2); // send 3 bits of id: COMMMAND
ht1632_writebits(command, 1<<7); // send the actual command
ht1632_writebits(0, 1); /* one extra dont-care bit in commands. */
ChipSelect(0);
}
//*********************************************************************************************************
/*
* ht1632_senddata
* send a nibble (4 bits) of data to a particular memory location of the
* ht1632. The command has 3 bit ID, 7 bits of address, and 4 bits of data.
* Select 1 0 1 A6 A5 A4 A3 A2 A1 A0 D0 D1 D2 D3 Free
* Note that the address is sent MSB first, while the data is sent LSB first!
* This means that somewhere a bit reversal will have to be done to get
* zero-based addressing of words and dots within words.
*/
void ht1632_senddata (byte chipNo, byte address, byte data)
{
ChipSelect(chipNo);
ht1632_writebits(HT1632_ID_WR, 1<<2); // send ID: WRITE to RAM
ht1632_writebits(address, 1<<6); // Send address
ht1632_writebits(data, 1<<3); // send 4 bits of data
ChipSelect(0);
}
//*********************************************************************************************************
/*
* Copy a character glyph from the myfont data structure to
* display memory, with its upper left at the given coordinate
* This is unoptimized and simply uses plot() to draw each dot.
* (fc, Jan 30/2011) display character using the specified color;
*/
void ht1632_putchar(int x, int y, char c, byte color)
{
// fonts defined for ascii 32 and beyond (index 0 in font array is ascii 32);
byte charIndex;
// replace undisplayable characters with blank;
if (c < 32 || c > 127)
{
charIndex = 0;
}
else
{
charIndex = c - 32;
}
// move character definition, pixel by pixel, onto the display;
// fonts are defined as one byte per row;
for (byte row=0; row<8; row++)
{
byte rowDots = pgm_read_byte_near(&myfont[charIndex][row]);
for (byte col=0; col<6; col++)
{
if (rowDots & (1<<(5-col)))
ht1632_plot(x+col, y+row, color);
else
ht1632_plot(x+col, y+row, color & PUTINSNAPSHOTRAM);
}
}
}
//*********************************************************************************************************
/*
* Copy a character glyph from the smallFont data structure to
* display memory, with its upper left at the given coordinate
* This is unoptimized and simply uses plot() to draw each dot.
*/
void ht1632_putSmallChar(int x, int y, char c, byte color)
{
// fonts defined for ascii 32 and beyond (index 0 in font array is ascii 32);
byte charIndex;
// replace undisplayable characters with blank;
if (c < 32 || c > 127)
{
charIndex = 0;
}
else
{
charIndex = c - 32;
}
// move character definition, pixel by pixel, onto the display;
// fonts are defined as one byte per row;
for (byte row=0; row<8; row++)
{
byte rowDots = pgm_read_byte_near(&smallFont[charIndex][row]);
for (byte col=0; col<6; col++)
{
if (rowDots & (1<<(5-col)))
ht1632_plot(x+col, y+row, color);
else
ht1632_plot(x+col, y+row, color & PUTINSNAPSHOTRAM);
}
}
}
//*********************************************************************************************************
/*
* Copy a character glyph from the proportional, largeFont data structure to
* display memory, with its upper left at the given coordinate.
* Font is 14 dots high and max 11 dots width.
* This is unoptimized and simply uses plot() to draw each dot.
*/
#ifdef _FONTLARGE_
int ht1632_putLargeChar(int x, int y, char c, byte color)
{
// fonts defined for ascii 32 and beyond (index 0 in font array is ascii 32);
byte charIndex, col, row;
// replace undisplayable characters with blank;
if (c < 32 || c > 127)
{
charIndex = 0;
}
else
{
charIndex = c - 32;
}
// move character definition, pixel by pixel, onto the display;
// Fonts are defined as up to 14 bit per row and max. 11 columns;
// first row is always zero to create the space between the characters;
for (col=0; col < 11; ++col) // max 11 columns;
{
uint16_t dots = pgm_read_word_near(&largeFont[charIndex][col]);
if (dots == 0) // stop if all bits zero;
break;
for (row=0; row < 14; row++)
{
if (dots & (0x4000 >> row)) // max 14 rows;
plot(x+col, y+row, color);
else
plot(x+col, y+row, color & PUTINSNAPSHOTRAM);
}
}
return x+col;
}
#endif
//*********************************************************************************************************
void displayStaticLine(char* text, byte y, byte color)
{
// try to center the text;
int len = strlen(text);
int nx = (X_MAX+1 - 6*len) / 2;
if (nx < 0)
{
nx = 0; // text too long to fit on the screen;
}
for (int i=0; i<len; i++)
{
ht1632_putSmallChar(nx + i*6, y, text[i], color);
}
}
//*********************************************************************************************************
/* (fc, Aug 1/10)
* display a big digit, defined on a 6x12 grid;
* the purpose is to display the time H12:MM on the 24x16 matrix;
*/
// (rp, Oct 2010) modified to use multiple big fonts;
void ht1632_putBigDigit(int x, int y, int digit, int fontNbr, byte color, int columns)
{
// move character definition, pixel by pixel, onto the display;
// a big digit is defined as 12 rows, one byte per row;
int fontOffset = fontNbr * CHARS_IN_FONT;
for (byte row=0; row < BYTES_PER_CHARS; row++)
{
byte rowDots = pgm_read_byte_near(&bigFont[digit + fontOffset][row]);
for (byte col=0; col<columns; col++)
{
if (rowDots & (1<<((columns - 1) - col)))
ht1632_plot(x+col, y+row, color);
else
ht1632_plot(x+col, y+row, color & PUTINSNAPSHOTRAM);
}
}
}
//*********************************************************************************************************
/* (fc, Jun 10/2011)
* load and display a given bitmap (defined in bitmaps.h);
*/
void ht1632_putBitmap(int x, int y, byte indexBmp, byte color)
{
if (color)
// move character definition, pixel by pixel, onto the display;
// bitmap has 14 rows x 14 columns, one WORD per row;
for (byte row=0; row < 14; row++)
{
uint16_t rowDots = pgm_read_word_near(&bitmap[indexBmp][row]);
for (byte col=0; col<14; col++)
{
if (rowDots & (1<<(13-col)))
ht1632_plot(x+col, y+row, color);
else
// little hack for pacman mode; comment for any other bitmap;
if (col > 0 || (row!=6 && row!=7))
ht1632_plot(x+col, y+row, color & PUTINSNAPSHOTRAM);
}
}
}
//*********************************************************************************************************
/*
* Copy a character glyph from the tinyFont data structure to
* display memory, with its upper left at the given coordinate
* This is unoptimized and simply uses plot() to draw each dot.
*/
void ht1632_putTinyChar(int x, int y, char c, byte color)
{
// fonts defined for ascii 32 and beyond (index 0 in font array is ascii 32);
byte charIndex;
// replace undisplayable characters with blank;
if (c < 32 || c > 126)
{
charIndex = 0;
}
else
{
charIndex = c - 32;
}
// move character definition, pixel by pixel, onto the display;
// fonts are defined as one byte per row;
for (byte row=0; row<6; row++)
{
byte rowDots = pgm_read_byte_near(&tinyFont[charIndex][row]);
for (byte col=0; col<4; col++)
{
if (rowDots & (1<<(3-col)))
ht1632_plot(x+col, y+row, color);
else
ht1632_plot(x+col, y+row, color & PUTINSNAPSHOTRAM);
}
}
}
void setBrightness(byte nLevel)
{
if (nLevel > 5)
nLevel = 5;
for (int i=1; i<=4; i++)
ht1632_sendcmd(i, HT1632_CMD_PWM + nLevel*3);
}