-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcoolSAA1064.cpp
769 lines (506 loc) · 21.9 KB
/
coolSAA1064.cpp
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
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
/**
* The 'coolSAA1064' library.
*
* SAA1064 saa1064;
* saa1064.scrollCooLSAA1064( );
*
* An arduino library driving the PHILIPS / NXP SAA1064 IC in a comfortable way.
*
* coolSAA1064 is distributed under the MIT License (MIT); this file is part of.
*
* Copyright (c) 2014-2024 Christian ([email protected])
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Christian
* created 20140215
* version 20200414
*/
/**************************************80**************************************/
#include <Wire.h> // I2C
#include "./coolSAA1064.h" // class header file
/**************************************80**************************************/
#if defined(ARDUINO) && ARDUINO >= 100
#define printIIC(args) Wire.write((uint8_t)args)
#define readIIC() Wire.read()
#else
#define printIIC(args) Wire.send(args)
#define readIIC() Wire.receive()
#endif
/**************************************80**************************************/
// Constructor
SAA1064::SAA1064( void ) {
_init( ); // init all
} // SAA1064
// Constructor
SAA1064::SAA1064( byte i2cAdress ) {
_init( ); // init all
_i2cAddress = i2cAdress; // overwrite i2c address set in _init( )
} // SAA1064
// Destructor
SAA1064::~SAA1064( void ) {
if( _arrDigits != 0 )
delete [ ] _arrDigits; // is allocated in member method _init( )
} // SAA1064
/**************************************80**************************************/
/**
* I wired the eight pins of the seven segement as they come in!
*
* 7-Segment: a -> SAA1064: P1 and/or P9 (pin: 10 and/or 15)
* 7-Segment: b -> SAA1064: P2 and/or P10 (pin: 9 and/or 16)
* 7-Segment: c -> SAA1064: P3 and/or P11 (pin: 8 and/or 17)
* 7-Segment: d -> SAA1064: P4 and/or P12 (pin: 7 and/or 18)
* 7-Segment: e -> SAA1064: P5 and/or P13 (pin: 6 and/or 19)
* 7-Segment: f -> SAA1064: P6 and/or P14 (pin: 5 and/or 20)
* 7-Segment: g -> SAA1064: P7 and/or P15 (pin: 4 and/or 21)
* 7-Segment: dp -> SAA1064: P8 and/or P16 (pin: 3 and/or 22)
*
* @author Christian
*/
void // sets the MAPPING TABLE (number to bytes) FOR the used WIRING
SAA1064::_init( void ) {
_i2cAddress = 0x70 >> 1; // shifted, due to pin 1 is grounded (VEE) -> 0x70
_arrDigitsLength = 30; // length of available char for single segment
_arrDigits = new byte[ _arrDigitsLength ]; // dynamic allocation -> del it!
// By the wiring above you can easily calculate the bytes by 2^p!
// However, you can use integer types directly as index for the
// set up array to display the integer on the seven segment. For
// example: int a = 4 .. _arrDigits[ a ] .. displays: value 4 or
// int a = 12 .. _arrDigits[ a ] .. displays: value C as HEX value.
_arrDigits[ 0 ] = (byte)( 63 ); // 0 : 1+2+4+8+16+32 = 63
_arrDigits[ 1 ] = (byte)( 6 ); // 1 : 2+4 = 6
_arrDigits[ 2 ] = (byte)( 91 ); // 2 : 1+2 +8+16 +64 = 91
_arrDigits[ 3 ] = (byte)( 79 ); // 3 : 1+2+4+8 +64 = 79
_arrDigits[ 4 ] = (byte)( 102 ); // 4 : 2+4 +32+64 = 102
_arrDigits[ 5 ] = (byte)( 109 ); // 5 : 1 +4+8 +32+64 = 109
_arrDigits[ 6 ] = (byte)( 125 ); // 6 : 1 +4+8+16+32+64 = 125
_arrDigits[ 7 ] = (byte)( 7 ); // 7 : 1+2+4 = 7
_arrDigits[ 8 ] = (byte)( 127 ); // 8 : 1+2+4+8+16+32+64 = 127
_arrDigits[ 9 ] = (byte)( 111 ); // 9 : 1+2+4+8+ +32+64 = 111
_arrDigits[ 10 ] = (byte)( 119 ); // A : 1+2+4 +16+32+64 = 119
_arrDigits[ 11 ] = (byte)( 124 ); // b : +4+8+16+32+64 = 124
_arrDigits[ 12 ] = (byte)( 57 ); // C : 1 +8+16+32 = 57
_arrDigits[ 13 ] = (byte)( 94 ); // d : 2+4+8+16 +64 = 94
_arrDigits[ 14 ] = (byte)( 121 ); // E : 1 +8+16+32+64 = 121
_arrDigits[ 15 ] = (byte)( 113 ); // F : 1 +16+32+64 = 113
_arrDigits[ 16 ] = (byte)( 116 ); // h : 4 +16+32+64 = 116
_arrDigits[ 17 ] = (byte)( 118 ); // H : 2+4 +16+32+64 = 118
_arrDigits[ 18 ] = (byte)( 31 ); // J : 1+2+4+8+16 = 31
_arrDigits[ 19 ] = (byte)( 56 ); // L : +8+16+32 = 56
_arrDigits[ 20 ] = (byte)( 84 ); // n : 4 +16 +64 = 84
_arrDigits[ 21 ] = (byte)( 92 ); // o : 4+8+16 +64 = 92
_arrDigits[ 22 ] = (byte)( 115 ); // P : 1+2 +16+32+64 = 115
_arrDigits[ 23 ] = (byte)( 80 ); // r : 16 +64 = 80
_arrDigits[ 24 ] = (byte)( 28 ); // u : 4+8+16 = 28
_arrDigits[ 25 ] = (byte)( 62 ); // U : 2+4+8+16+32 = 62
_arrDigits[ 26 ] = (byte)( 110 ); // Y : 2+4+8 +32+64 = 64
_arrDigits[ 27 ] = (byte)( 64 ); // - : +64 = 64
_arrDigits[ 28 ] = (byte)( 15 ); // ] : 1+2+4+8 = 15
_arrDigits[ 29 ] = (byte)( 99 ); // ° : 1+2 +32+64 = 99
} // SAA1064::_init
/**************************************80**************************************/
void // call this in your arduino setup() method; see issue #1
SAA1064::setup( ) {
Wire.begin( ); // due to reported issue #1; opening wire by calling setup()
} // SAA1064::begin
void // set to your own control byte
SAA1064::set( byte controlByte ) {
_set( controlByte );
} // SAA1064::set
/**************************************80**************************************/
void // switch all segmetns on for testing them with 3 mA
SAA1064::setTest( ) {
_set( B00011111 );
} // SAA1064::setTest
/**************************************80**************************************/
void // set up to a static mode: 2 digits and 21 mA as maximum
SAA1064::setStatic( ) {
_set( B01110110 );
} // SAA1064::setStatic
/**************************************80**************************************/
void // set up to dynamic mode: 4 digits and 21 mA as maximum
SAA1064::setDynamic( ) {
_set( B01110111 );
} // SAA1064::setDynamic
/**************************************80**************************************/
void // set to output currents 3 mA; B0001xxxx
SAA1064::setDark( void ) {
setIntensity( 1 );
} // SAA1064::setDark
/**************************************80**************************************/
void // set to output currents 12 mA; B0100xxxx
SAA1064::setNormal( void ) {
setIntensity( 4 );
} // SAA1064::setNormal
/**************************************80**************************************/
void // set to output currents 21 mA = 3 + 6 + 12 mA; B0111xxxx
SAA1064::setBright( void ) {
setIntensity( 7 );
} // SAA1064::setBright
/**************************************80**************************************/
void // sets the intense from 1 .. 7 - min .. max
SAA1064::setIntensity( int intensity ) {
if( intensity < 1 )
intensity = 1; // become fail safe
if( intensity > 7 )
intensity = 7; // become fail safe
byte byteIntensity = (byte)(intensity); // cast to bits n bytes
byteIntensity = byteIntensity << 4; // B00000111 -> B01110000
byte controlByte = _controlByte; // get control byte from mind
controlByte = controlByte % B00001000; // isolation of config bytes
controlByte += byteIntensity; // add up all pos of 3 mA, 6 mA, and 12 mA
set( controlByte ); // send via I2C and keep in mind
} // SAA1064::setIntensity
/**************************************80**************************************/
void // switch off all segments
SAA1064::clear( ) {
say( -1, -1, -1, -1 ); // use number methode; -1 is code for blank
} // SAA1064::clear
/**************************************80**************************************/
void // update display directly by hex number: 0 .. F and -1 is blank
SAA1064::say( int h4, int h3, int h2, int h1 ) {
byte b4 = 0, b3 = 0, b2 = 0, b1 = 0;
if( h4 < 0 || h4 > _arrDigitsLength ) // secure a valid input of known digits
b4 = 0; // blank this segment
else
b4 = _arrDigits[ h4 ]; // convert to digit to code in bytes
if( h3 < 0 || h3 > _arrDigitsLength ) // secure a valid input of known digits
b3 = 0; // blank this segment
else
b3 = _arrDigits[ h3 ]; // convert to digit to code in bytes
if( h2 < 0 || h2 > _arrDigitsLength ) // secure a valid input of known digits
b2 = 0; // blank this segment
else
b2 = _arrDigits[ h2 ]; // convert to digit to code in bytes
if( h1 < 0 || h1 > _arrDigitsLength ) // secure a valid input of known digits
b1 = 0; // blank this segment
else
b1 = _arrDigits[ h1 ]; // convert to digit to code in bytes
_say( b4, b3, b2, b1 ); // cast them
} // SAA1064::say
/**************************************80**************************************/
void // update display directly by hex number: 0 .. F and -1 is blank
SAA1064::say( byte b4, byte b3, byte b2, byte b1 ) {
_say( b4, b3, b2, b1 ); // cast them
} // SAA1064::say
/**************************************80**************************************/
void // say byte on single digit: 0, 1, 2 or 3
SAA1064::say( int h, int digit ) {
byte b = 0;
if( h < 0 || h > _arrDigitsLength ) // secure a valid input of known digits
b = 0; // blank this segment
else
b = _arrDigits[ h ]; // convert to digit to code in bytes
_say( b, digit ); // say digit on chosen position
} // SAA1064::say
/**************************************80**************************************/
void // say byte on single digit: 0, 1, 2 or 3
SAA1064::say( byte b, int digit ) {
_say( b, digit );
} // SAA1064::say
/**************************************80**************************************/
void // say a number 0 .. 9999 : 42 => 42
SAA1064::say( int number ) {
int digits[ 4 ]; // allocate memory for split2digit method
_splitNum2Dig( number, digits ); // splt 2 array of digits
if( digits[ 3 ] == 0 )
digits[ 3 ] = -1; // library internal code for blanking segement
if( digits[ 2 ] == 0 && number < 100 )
digits[ 2 ] = -1; // library internal code for blanking segement
if( digits[ 1 ] == 0 && number < 10 )
digits[ 1 ] = -1; // library internal code for blanking segement
say( digits[ 3 ], digits[ 2 ], digits[ 1 ], digits[ 0 ] );
} // SAA1064::say
/**************************************80**************************************/
void // say a number 0 .. 9999 : 42 => 0042
SAA1064::sayByZero( int number ) {
int digits[ 4 ]; // allocate memory for split2digit method
_splitNum2Dig( number, digits ); // splt 2 array of digits
say( digits[ 3 ], digits[ 2 ], digits[ 1 ], digits[ 0 ] );
} // SAA1064::say
/**************************************80**************************************/
void // scroll right to left by 250 ms per step
SAA1064::scroll( int* arrDigits, int arrDigitsLength, int milliSeconds ) {
int d4 = -1, d3 = -1, d2 = -1, d1 = -1;
if( milliSeconds < 10 )
milliSeconds = 10;
for( int i = 0; i < arrDigitsLength; i++ ) {
if( i > 2 )
d4 = d3;
if( i > 1 )
d3 = d2;
if( i > 0 )
d2 = d1;
d1 = arrDigits[ i ];
clear( );
say( d1, 0 );
say( d2, 1 );
say( d3, 2 );
say( d4, 3 );
delay( milliSeconds );
} // i
} // SAA1064::scroll
/**************************************80**************************************/
void // scroll 'CooL SAA1064 8-]' from right to left
SAA1064::scrollCooLSAA1064( void ) {
int arr[ 20 ] = { 12, 21, 21, 19, -1,
5, 10, 10, 1, 0, 6, 4, -1,
8, 27, 28, -1, -1, -1 ,-1 }; // hex + interal codes
scroll( arr, 20, 250 ); // scroll right to left by 250 ms per step
} // SAA1064::scrollCooLSAA1064
/**************************************80**************************************/
void // display an amplitude by level form 0 .. 7
SAA1064::amplitude( int level ) {
byte b4 = 0, b3 = 0, b2 = 0, b1 = 0;
clear( );
if( level < 0 )
level = 0;
if( level > 7 )
level = 7;
switch ( level ) {
case 0: b4 = 0; b3 = 0; b2 = 0; b1 = 6; break;
case 1: b4 = 0; b3 = 0; b2 = 0; b1 = 54; break;
case 2: b4 = 0; b3 = 0; b2 = 6; b1 = 54; break;
case 3: b4 = 0; b3 = 0; b2 = 54; b1 = 54; break;
case 4: b4 = 0; b3 = 6; b2 = 54; b1 = 54; break;
case 5: b4 = 0; b3 = 54; b2 = 54; b1 = 54; break;
case 6: b4 = 6; b3 = 54; b2 = 54; b1 = 54; break;
case 7: b4 = 54; b3 = 54; b2 = 54; b1 = 54; break;
} // switch
say( b4, b3, b2, b1 );
} // SAA1064::amplitude
/**************************************80**************************************/
void // displays the time
SAA1064::sayTime( int hour, int minute ) {
int h1 = 0, h0 = 0, m1 = 0, m0 = 0;
int digits[ 4 ];
_splitNum2Dig( hour, digits );
h1 = digits[ 1 ];
h0 = digits[ 0 ];
_splitNum2Dig( minute, digits );
m1 = digits[ 1 ];
m0 = digits[ 0 ];
say( h1, h0, m1, m0 );
} // SAA1064::sayTime
/**************************************80**************************************/
void // displays the date
SAA1064::sayDate( int day, int month ) {
sayTime( day, month ); // same method, fliped positions
} // sayDate
/**************************************80**************************************/
void // displays the date
SAA1064::sayDateUS( int day, int month ) {
sayTime( month, day ); // same method, fliped positions
} // sayDate
/**************************************80**************************************/
void // say year in four digits
SAA1064::sayYear( int year ) {
say( year );
} // SAA1064::sayYear
/**************************************80**************************************/
void // scroll right to left
SAA1064::scrollTime( int hour, int minute, int second, int milliSeconds ) {
int h1 = 0, h0 = 0, m1 = 0, m0 = 0, s1 = 0, s0 = 0;
int digits[ 4 ];
_splitNum2Dig( hour, digits );
h1 = digits[ 1 ];
h0 = digits[ 0 ];
_splitNum2Dig( minute, digits );
m1 = digits[ 1 ];
m0 = digits[ 0 ];
_splitNum2Dig( second, digits );
s1 = digits[ 1 ];
s0 = digits[ 0 ];
int arrTimeLength = 12; // '27' -> '-', a minus or '-1' -> ' ', blank
int arrTime[ 12 ] = { h1, h0, 27, m1, m0, 27, s1, s0, -1, -1, -1, -1 };
scroll( arrTime, arrTimeLength, milliSeconds );
} // SAA1064::scrollTime
/**************************************80**************************************/
void // scroll right to left
SAA1064::scrollDate( int day, int month, int year, int milliSeconds ) {
int d1 = 0, d0 = 0, m1 = 0, m0 = 0, y3 = 0, y2 = 0, y1 = 0, y0 = 0;
int digits[ 4 ];
_splitNum2Dig( day, digits );
d1 = digits[ 1 ];
d0 = digits[ 0 ];
_splitNum2Dig( month, digits );
m1 = digits[ 1 ];
m0 = digits[ 0 ];
_splitNum2Dig( year, digits );
y3 = digits[ 3 ];
y2 = digits[ 2 ];
y1 = digits[ 1 ];
y0 = digits[ 0 ];
int arrDateLength = 14; // '27' -> '-', a minus or '-1' -> ' ', blank
int arrDate[ 14 ] = { d1, d0, 27, m1, m0, 27, y3, y2, y1, y0, -1, -1, -1, -1 };
scroll( arrDate, arrDateLength, milliSeconds );
} // SAA1064::scrollDate
/**************************************80**************************************/
void // displays the word On
SAA1064::sayOn( void ) {
say( -1, -1, 21, 20 );
} // SAA1064::sayOn
/**************************************80**************************************/
void // displays the word OFF
SAA1064::sayOFF( void ) {
say( -1, 0, 21, 15 ); // HEX => 15 == F
} // SAA1064::sayOFF
/**************************************80**************************************/
void // displays the word gO
SAA1064::sayGO( void ) {
say( -1, -1, 9, 21 );
} // SAA1064::sayG0
/**************************************80**************************************/
void // displays the word OPEn
SAA1064::sayOPEn( void ) {
say( 0, 22, 14, 20 );
} // SAA1064::sayOPEn
/**************************************80**************************************/
void // displays the word LOAd
SAA1064::sayLOAd( void ) {
say( 19, 21, 10, 13 ); // HEX; 10 = A and 13 = d
} // SAA1064::sayLOAd
/**************************************80**************************************/
void // displays the word PLAY
SAA1064::sayPLAY( void ) {
say( 22, 19, 10, 26 );
} // SAA1064::sayPLAY
/**************************************80**************************************/
void // displays the word dISC
SAA1064::sayDISC( void ) {
say( 94, 6, 5, 12 );
} // SAA1064::sayDISC
/**************************************80**************************************/
void // displays the word Cool
SAA1064::sayCooL( void ) {
say( 12, 21, 21, 19 ); // Hex: 12 -> C, and internal codes for more digits
} // SAA1064::sayCooL
/**************************************80**************************************/
void // displays the word OooH
SAA1064::sayOooh( void ) {
say( 0, 21, 21, 16 ); // Hex: 0 -> O, and internal codes for more digits
} // SAA1064::sayOooh
/**************************************80**************************************/
void // displays the word UuuH
SAA1064::sayUuuh( void ) {
say( 25, 24, 24, 16 ); // internal codes for more digits
} // SAA1064::sayUuuh
/**************************************80**************************************/
void // displays the word AAAh
SAA1064::sayAAAh( void ) {
say( 10, 10, 10, 16 ); // internal codes for more digits
} // SAA1064::sayAAAh
/**************************************80**************************************/
void // displays the word Cool
SAA1064::sayHAhA( void ) {
say( 17, 10, 16, 10 ); // 17 -> H, and internal codes for more digits
} // SAA1064::sayCool
/**************************************80**************************************/
void // displays the word JAJA
SAA1064::sayJAJA( void ) {
say( 18, 10, 18, 10 ); // 10 -HEX-> A, 18 -INTERNAL-> J
} // SAA1064::sayJAJA
/**************************************80**************************************/
void // displays the word Foo
SAA1064::sayFoo( void ) {
say( -1, 15, 21, 21 ); // 15 -> F, and internal codes for more digits
} // SAA1064::sayFoo
/**************************************80**************************************/
void // displays the word bAR
SAA1064::saybAr( void ) {
say( -1, 11, 10, 23 ); // 11 -> b, 10 -> A, 23 -> r
} // SAA1064::saybAr
/**************************************80**************************************/
void // displays a smiley 8-]
SAA1064::saySmiley( void ) {
say( (byte)(0), (byte)(127), byte(64), byte(15) );
} // SAA1064::saySmiley
/**************************************80**************************************/
void // bytes through all segements by a loop
SAA1064::byteAll( void ) {
for( int i = 0; i < 253; i++ ) {
_say( (byte)( i+3 ), (byte)( i+2 ), (byte)( i+1 ), (byte)( i ) );
delay( 100 );
} // i
} // SAA1064::byteAll
void // show the member _arrDigits with stored codes.
SAA1064::sayArrDigits( void ) {
for( int i = 0; i < _arrDigitsLength; i++ ) {
_say( _arrDigits[ i ], _arrDigits[ i ], _arrDigits[ i ], _arrDigits[ i ] );
delay( 1000 );
} // i
} // SAA1064::sayArrDigits
/**************************************80**************************************/
/**************************************80**************************************/
/**************************************80**************************************/
void // set a control byte and keep it in mind
SAA1064::_set( byte controlByte ) {
_controlByte = controlByte; // store given control byte to member var
Wire.beginTransmission( _i2cAddress );
Wire.write( B00000000 ); // instruction byte: 0 -> next is the control byte
Wire.write( _controlByte ); // have a look in the data sheet for details
Wire.endTransmission( );
} // SAA1064::_set
/**************************************80**************************************/
void // update display directly by bytes
SAA1064::_say( byte b4, byte b3, byte b2, byte b1 ) {
Wire.beginTransmission( _i2cAddress );
Wire.write( B00000001 ); // instruction byte -> RHS digit, 2nd, 3rd, last
Wire.write( b1 ); // digit 1 (RHS)
Wire.write( b2 ); // digit 2
Wire.write( b3 ); // digit 3
Wire.write( b4 ); // digit 4 (LHS)
Wire.endTransmission( );
} // SAA1064::_say
void // say byte on single digit: 0, 1, 2 or 3
SAA1064::_say( byte b, int digit ) {
if( digit < 0 || digit > 3 )
digit = 0; // fall back to first digit
Wire.beginTransmission( _i2cAddress );
Wire.write( (byte)( digit + 1 ) ); // instruction byte -> 1st, 2nd, 3rd, last
Wire.write( b ); // digit 4 (LHS)
Wire.endTransmission( );
} // SAA1064::_say
/**************************************80**************************************/
/**
* Method for splitting up a numbers into its place-value notation.
*
* Renamed the method and the variables inside.
* @author Christian
* @date 15.02.2014
*
* Original by: http://tronixstuff.com/tutorials/ => Ch. 39 - NXP SAA1064
* Creative Commons Attribution-Non Commercial-Share Alike v3.0 license
* http://creativecommons.org/licenses/by-nc-sa/3.0/
* @author John Boxall
* @date 27.07.2011
*/
void // and returns an array of length 4; allocated before !!!
SAA1064::_splitNum2Dig( int number, int* digits ) {
int thousand = number / 1000; // 1234 -> 1
int hundred = ( number - ( thousand * 1000 ) ) / 100; // 1234 -> 234 -> 2
int ten = ( number - ( thousand * 1000 + hundred * 100 ) ) / 10; // 1234 -> 34 -> 3
int one = number - ( thousand * 1000 + hundred * 100 + ten * 10 ); // 1234 -> 4
digits[ 3 ] = thousand;
digits[ 2 ] = hundred;
digits[ 1 ] = ten;
digits[ 0 ] = one;
} // SAA1064::_splitNum2Dig
/**************************************80**************************************/