-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
FlipDisc.cpp
1490 lines (1317 loc) · 70.6 KB
/
FlipDisc.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
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*----------------------------------------------------------------------------------*
* FlipDisc.cpp - Arduino library for flip-disc displays. *
* This library is intended for use with the displays designed by *
* www.Flipo.io - Marcin Saj. *
* *
* The MIT License *
* Marcin Saj 15 Jan 2023 *
* https://github.com/marcinsaj/FlipDisc *
*----------------------------------------------------------------------------------*/
#include "FlipDisc.h"
/*
* Declaration of the flip-disc display enable pin
* EN_PIN - the pin serves as a latch for shift registers on which
* the controllers built into the displays are based.
*/
uint16_t _EN_PIN = 0; // Start & End SPI transfer data
/*
* Declaration of the Pulse Shaper Power Supply Module control pins
*/
uint16_t _CH_PIN = 0; // Charging PSPS module - turn ON/OFF
uint16_t _PL_PIN = 0; // Release the current pulse - turn ON/OFF
uint8_t flip_delay = 0; // Variable for the delay effect between flip discs
uint32_t time_now = 0; // Variable for the millis() function
/*
* 2-dimensional array with 3 columns.
* The first column lists all connected displays "module_type_column",
* the second column is the number of data bytes required to control the display "number_bytes_column",
* the third column is a number defining the relative position of the modules
* in relation to each other and for each type separately "module_relative_position_column".
*/
uint8_t moduleInitArray[8][3];
/*
* An array of defined display names:
* -> D7SEG - 7-Segment flip-disc display
* -> D2X1 - 2x1 flip-disc display
* -> D3X1 - 3x1 flip-disc display
* -> D1X3 - 1x3 flip-disc display
* -> D1X7 - 1x7 flip-disc display
* -> D2X6 - 2x6 flip-disc display
* -> D3X3 - 3x3 flip-disc display
* -> D3X4 - 3x4 flip-disc display
* -> D3X5 - 3x5 flip-disc display
*/
static const uint8_t moduleTypeArray[] PROGMEM = {D7SEG, D2X1, D3X1, D1X3, D1X7, D2X6, D3X3, D3X4, D3X5};
/*
* Total length of data frame for all displays.
* We can only control one disc out of all connected display modules at a time.
* Despite the fact that we only need two bits to control one disc, we have to send
* a data frame of a length equal to the sum of the data for all displays each time.
* If there is no display module declaration, each empty module up to eight
* is supplemented with 3 bytes (largest display requires 3 bytes of data).
* If the user does not declare the connected display, incorrect operation
* or damage to the display may occur (thats why these 3 bytes).
*/
uint8_t number_all_bytes = 0;
/*----------------------------------------------------------------------------------*
* Constructor *
*----------------------------------------------------------------------------------*/
FlipDisc::FlipDisc()
{
/* Do nothing */
}
/*----------------------------------------------------------------------------------*
* Initialization function for a series of displays. The function has 1 default *
* argument and 7 optional arguments. The function also prepares SPI. *
* Correct initialization requires code names of the serially connected displays. *
*----------------------------------------------------------------------------------*/
void FlipDisc::Init(uint8_t MOD1, uint8_t MOD2 /* = 0xFF */, uint8_t MOD3 /*= 0xFF */,
uint8_t MOD4 /* = 0xFF */, uint8_t MOD5 /*= 0xFF */,
uint8_t MOD6 /* = 0xFF */, uint8_t MOD7 /*= 0xFF */,
uint8_t MOD8 /* = 0xFF */)
{
// SPI initialization
SPI.begin();
// First charging Pulse Shaper Power Supply module after power up the device
PrepareCurrentPulse();
// Saving a list of displays to the array
moduleInitArray[0][module_type_column] = MOD1;
moduleInitArray[1][module_type_column] = MOD2;
moduleInitArray[2][module_type_column] = MOD3;
moduleInitArray[3][module_type_column] = MOD4;
moduleInitArray[4][module_type_column] = MOD5;
moduleInitArray[5][module_type_column] = MOD6;
moduleInitArray[6][module_type_column] = MOD7;
moduleInitArray[7][module_type_column] = MOD8;
/*
* module_relative_position variable
* for example, if there is a D7SEG, D3X1, D7SEG, D7SEG, D3X1, D1X3 in a series
* of displays, then the relative positions will be 1, 1, 2, 3, 2, 1.
* Each type of display is counted separately.
* In simple terms, it can be presented as a separate list for each
* type of display and numbered starting from 1. Determining
* the relative position of the display is used to simplify the display
* handling functions.
*/
uint8_t module_relative_position = 0;
uint8_t module_type = 0;
uint8_t module_number_types = sizeof(moduleTypeArray);
// For all types of displays
for(int i = 0; i < module_number_types; i++)
{
// The initial value of the relative position for each type of the display
module_relative_position = 0;
// Reading the first type of display to check
module_type = pgm_read_byte(&moduleTypeArray[i]);
// For the selected display type, search the entire list of serially connected displays
for(int j = 0; j < 8; j++)
{
// If the selected display type is found in the list
// then the relative position is incremented and stored in the array
if(moduleInitArray[j][module_type_column] == module_type)
{
module_relative_position = module_relative_position + 1;
moduleInitArray[j][module_relative_position_column] = module_relative_position;
}
}
}
/*
* Extracting the number of data bytes of each display type, the number of bytes
* determines the size of the control frame. Required by the displays architecture,
* which is based on shift registers.
* If the user does not declare the connected display, incorrect operation or
* damage to the display may occur. Therefore, if there is no display module
* declaration, each empty module up to eight is supplemented with 3 bytes.
* We can only handle one disc from the entire display series at a time, so it is
* very important where in the data stream to put the control bits for the selected
* disc. In fact, with a data frame of a few or a dozen bytes, only two bits are
* set to "1" the rest of the data is "0".
*/
uint8_t number_bytes = 0;
for(int i = 0; i < 8; i++)
{
switch (moduleInitArray[i][module_type_column])
{
case D7SEG:
number_bytes = 3;
break;
/* D3X1 = D2X1 - are the same */
case D3X1:
number_bytes = 1;
break;
case D1X3:
number_bytes = 1;
break;
case D1X7:
number_bytes = 2;
break;
case D2X6:
number_bytes = 2;
break;
case D3X3:
number_bytes = 2;
break;
case D3X4:
number_bytes = 2;
break;
case D3X5:
number_bytes = 2;
break;
case NONE:
number_bytes = 3;
break;
default:
number_bytes = 3;
break;
}
// Saving data about the number of data bytes required by the module
moduleInitArray[i][number_bytes_column] = number_bytes;
// Total length of data frame for all displays.
number_all_bytes = number_all_bytes + number_bytes;
}
}
/*----------------------------------------------------------------------------------*
* Function to control up to eight 7-Segment displays. *
* The first argument is the default and the others are optional. *
* This function allows you to display numbers and symbols: 0-9, "°", "C", "F", etc.*
*----------------------------------------------------------------------------------*/
void FlipDisc::Matrix_7Seg(uint8_t data1, uint8_t data2 /* = 0xFF */, uint8_t data3 /* = 0xFF */,
uint8_t data4 /* = 0xFF */, uint8_t data5 /* = 0xFF */,
uint8_t data6 /* = 0xFF */, uint8_t data7 /* = 0xFF */,
uint8_t data8 /* = 0xFF */)
{
// Saving a list of data to the array
uint8_t newDataArray[8] = {data1, data2, data3, data4, data5, data6, data7, data8};
for(int i = 0; i < 8; i++)
{
// Call the function to handle the display only if there is data for it
if(newDataArray[i] != 0xFF) Display_7Seg(i + 1, newDataArray[i]);
}
}
/*----------------------------------------------------------------------------------*
* The function allows you to control one 7-Segment display. *
* The first argument is the relative number of the display in the series *
* of all displays. For example, if we have a combination of D7SEG, D3X1, D7SEG then*
* the second D7SEG display will have a relative number of 2 even though there *
* is a D3X1 display between the D7SEG displays. *
* -> module_number - relative number of the "D7SEG" display *
* -> data. *
* *
* Brief: *
* The display consists of 23 discs. The displayArray_7Seg[][] array contains *
* information about all disc statuses for the symbol we want to display. *
* To flip a selected disc, we need to know the corresponding control outputs. *
* Disc statuses "0" and "1" correspond to different control outputs. *
* The list of information about all control outputs for corresponding *
* disc statuses of all discs and the currently selected digit/symbol to be *
* displayed are contained in two tables: *
* -> setDiscArray_7Seg[][] - "1" *
* -> resetDiscArray_7Seg[][] - "0" *
*----------------------------------------------------------------------------------*/
void FlipDisc::Display_7Seg(uint8_t module_number, uint8_t new_data)
{
/*
* Simple protection from user error.
* If the selected display has not been declared in Init() then the function will not execute.
*/
if(Fuse(module_number, D7SEG) == true) return;
bool disc_status = 0;
uint8_t bit_number = 0;
uint8_t current_column = 0;
uint8_t current_row = new_data;
// The display is built with 23 independently controlled flip-discs
for(int disc_number = 0; disc_number < 23; disc_number++)
{
/*
* bit_number can only be in the range 0-7, so we must make sure that
* when changing the columns/bytes to read, start counting the bits again from 0.
*/
if(disc_number < 8) {bit_number = disc_number; current_column = 0;}
if((disc_number >= 8) && (disc_number < 16)) {bit_number = disc_number - 8; current_column = 1;}
if(disc_number >= 16) {bit_number = disc_number - 16; current_column = 2;}
/*
* 1 - Read one byte from location: displayArray_7Seg[current_row][current_column]
* 2 - Shift byte from 0 to 7 bits to the right
* 3 - Extract the bit that corresponds to the state of the selected display disc
*/
disc_status = ((pgm_read_byte(&displayArray_7Seg[current_row][current_column])) >> (bit_number)) & 0b00000001;
// Flip one selected disc
Disc_7Seg(module_number, disc_number, disc_status);
}
// Finally, clear all display outputs
ClearAllOutputs();
}
/*----------------------------------------------------------------------------------*
* The function allows you to control one selected disc of 7-Segment display. *
* The first argument is the relative number of the display in the series *
* of all displays. For example, if we have a combination of D7SEG, D3X1, D7SEG then*
* the second D7SEG display will have a relative number of 2 even though there *
* is a D3X1 display between the D7SEG displays. The second argument disc_number *
* is the number of selected disc 0-22 of the 7-Segment display. *
* The third argument is the status of the selected disc *
* -> module_number - relative number of the "D7SEG" display *
* -> disc_number - there are 23 discs in 7-Segment display 0-22 *
* -> disc_status - reset disc "0" or set disc "1" *
* *
* 0 1 2 3 4 *
* 19 5 *
* 18 6 *
* 17 20 21 22 7 *
* 16 8 *
* 15 9 *
* 14 13 12 11 10 *
* *
* Brief: *
* The display consists of 23 discs. *
* To flip a selected disc, we need to know the corresponding control outputs. *
* Disc statuses "0" and "1" correspond to different control outputs. *
* The list of information about all control outputs for corresponding *
* disc statuses of all discs are contained in two tables: *
* -> setDiscArray_7Seg[][] - "1" *
* -> resetDiscArray_7Seg[][] - "0" *
*----------------------------------------------------------------------------------*/
void FlipDisc::Disc_7Seg(uint8_t module_number, uint8_t disc_number, bool disc_status)
{
// Start of SPI data transfer
digitalWrite(_EN_PIN, LOW);
/*
* Send blank data "0" to all control outputs of the other displays BEFORE
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D7SEG, BEFORE);
/*
* Each of the discs has two sides, one side corresponds to the disk status "1" - color,
* the other side "0" - black.
* Each of the "0" or "1" statuses requires a different polarity of the current pulse
* released into the disc, and thus for each of the statuses we must drive different
* controller outputs to achieve the desired effect.
* The list of information about the statuses of all discs for the entire display
* and the currently selected digit/symbol to be displayed is contained in two tables:
* -> setDiscArray_7Seg[][] - "1"
* -> resetDiscArray_7Seg[][] - "0"
* The arrays contains the addresses of all control outputs corresponding to the setting
* of the discs to the "color" side or "black" side.
* Each separate display disc requires 3 bytes of data to be transferred.
* To flip the entire display, we need to send 3 bytes x 23 discs = 69 bytes of data
*/
for(int byte_number = 0; byte_number < 3; byte_number++)
{
if(disc_status == 0) SPI.transfer(pgm_read_byte(&setDiscArray_7Seg[disc_number][byte_number]));
if(disc_status == 1) SPI.transfer(pgm_read_byte(&resetDiscArray_7Seg[disc_number][byte_number]));
}
/*
* Send blank data "0" to all control outputs of the other displays AFTER
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D7SEG, AFTER);
// End of SPI data transfer
digitalWrite(_EN_PIN, HIGH);
// Release of 1ms current pulse
ReleaseCurrentPulse();
}
/*----------------------------------------------------------------------------------*
* Function allows you to control a selected disc in a selected dot display. *
* We can control only one dot of the selected display at a time. *
* The first argument module_number is the relative number of the display in *
* the series of all displays. For example, if we have a combination *
* of D3X1, D7SEG, D3X1, then the second D3X1 display will have a relative number *
* of 2 even though there is a D7SEG display between the D3X1 displays. *
* -> module_number - relative number of the "D3X1" display *
* -> disc_number - display disc number counting from top to bottom 1-3 *
* -> disc_status - reset disc "0" or set disc "1" *
*----------------------------------------------------------------------------------*/
void FlipDisc::Disc_3x1(uint8_t module_number, uint8_t disc_number, bool disc_status)
{
/*
* Simple protection from user error.
* If the selected display has not been declared in Init() then the function will not execute.
*/
if(Fuse(module_number, D3X1) == true) return;
uint8_t newDiscArray[3];
/*
* disc_number - display dot number counting from top to bottom 1, 2, 3
* The array row numbers newDiscArray[] start at 0 so we need to subtract 1 (i-1)
* If we assign the value 0xFF to discs, the Display_3x1() function will ignore these discs
*/
for(int i = 1; i <= 3; i++)
{
if(disc_number == i) newDiscArray[i-1] = disc_status;
else newDiscArray[i-1] = 0xFF;
}
// Call the function to flip the dot (only one disc)
Display_3x1(module_number, newDiscArray[0], newDiscArray[1], newDiscArray[2]);
// Clear all outputs of the controllers built into the displays
ClearAllOutputs();
}
/*----------------------------------------------------------------------------------*
* Same functionality as Disc_3x1()function but to handle display 2x1 *
*----------------------------------------------------------------------------------*/
void FlipDisc::Disc_2x1(uint8_t module_number, uint8_t disc_number, bool disc_status)
{
Disc_3x1(module_number, disc_number, disc_status);
}
/*----------------------------------------------------------------------------------*
* The function allows you to control 2x1 or 3x1 display. *
* You can control one, two or three discs of the selected display at a time. *
* The first argument is the relative number of the display in the series *
* of all displays. For example, if we have a combination of D3X1, D7SEG, D3X1, *
* then the second D3X1 display will have a relative number of 2 even though there *
* is a D7SEG display between the D3X1 displays. *
* -> module_number - relative number of the "D3X1" display *
* -> disc1, disc2, disc3. *
* *
* Brief: *
* The display consists of 2 or 3 discs. *
* To flip a selected disc, we need to know the corresponding control outputs. *
* The list of information about control outputs for corresponding discs *
* to be displayed are contained in two tables: *
* -> setDiscArray_3x1[] - "1" *
* -> resetDiscArray_3x1[] - "0" *
*----------------------------------------------------------------------------------*/
void FlipDisc::Display_3x1(uint8_t module_number, uint8_t disc1 /* = 0xFF */, uint8_t disc2 /* = 0xFF */, uint8_t disc3 /* = 0xFF */)
{
/*
* Simple protection from user error.
* If the selected display has not been declared in Init() then the function will not execute.
*/
if(Fuse(module_number, D3X1) == true) return;
// Saving a list of dot statuses to the array
uint8_t newDiscArray[3] = {disc1, disc2, disc3};
// 3 D3X1 - 3 loops
for(int disc = 0; disc < 3; disc++)
{
// Check if we have new data for dot. 0xFF - no data
if(newDiscArray[disc] != 0xFF)
{
// Start of SPI data transfer
digitalWrite(_EN_PIN, LOW);
/*
* Send blank data "0" to all control outputs of the other displays BEFORE
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D3X1, BEFORE);
/*
* Each of the discs has two sides, one side corresponds to the disk status "1" - color,
* the other side "0" - black.
* Each of the "0" or "1" statuses requires a different polarity of the current pulse
* released into the disc, and thus for each of the statuses we must drive different
* controller outputs to achieve the desired effect.
* The list of information about the statuses of all discs for the display
* and the currently selected dot to be displayed is contained in two tables:
* -> setDiscArray_3x1[] - "1"
* -> resetDiscArray_3x1[] - "0"
* Each separate display disc requires 1 byte of data to be transferred.
* To flip all 3 discs, we need to send 3 bytes of data.
*/
if(newDiscArray[disc] == 1) SPI.transfer(pgm_read_byte(&setDiscArray_3x1[disc]));
if(newDiscArray[disc] == 0) SPI.transfer(pgm_read_byte(&resetDiscArray_3x1[disc]));
/*
* Send blank data "0" to all control outputs of the other displays AFTER
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D3X1, AFTER);
// End of SPI data transfer
digitalWrite(_EN_PIN, HIGH);
// Release of 1ms current pulse
ReleaseCurrentPulse();
}
}
// Finally, clear all display outputs
ClearAllOutputs();
}
/*----------------------------------------------------------------------------------*
* Same functionality as Display_3x1()function but to handle only two discs *
*----------------------------------------------------------------------------------*/
void FlipDisc::Display_2x1(uint8_t module_number, uint8_t disc1 /* = 0xFF */, uint8_t disc2 /* = 0xFF */)
{
Display_3x1(module_number, disc1, disc2);
}
/*----------------------------------------------------------------------------------*
* Function allows you to control selected disc in a 1x3 display. *
* We can control only one disc of the selected display at a time. *
* The first argument module_number is the relative number of the display in *
* the series of all displays. For example, if we have a combination *
* of D1X3, D7SEG, D1X3, then the second D1X3 display will have a relative number *
* of 2 even though there is a D7SEG display between the D1X3 displays. *
* -> module_number - relative number of the "D1X3" display *
* -> disc_number - display disc number counting from left to right 1-3 *
* -> disc_status - reset disc "0" or set disc "1" *
*----------------------------------------------------------------------------------*/
void FlipDisc::Disc_1x3(uint8_t module_number, uint8_t disc_number, bool disc_status)
{
/*
* Simple protection from user error.
* If the selected display has not been declared in Init() then the function will not execute.
*/
if(Fuse(module_number, D1X3) == true) return;
uint8_t newDiscArray[3];
/*
* disc_number - counting from left to right 1, 2, 3
* The array row numbers newDiscArray[] start at 0 so we need to subtract 1 (i-1)
* If we assign the value 0xFF to discs, the Display_1x3() function will ignore these discs
*/
for(int i = 1; i <= 3; i++)
{
if(disc_number == i) newDiscArray[i-1] = disc_status;
else newDiscArray[i-1] = 0xFF;
}
// Call the function to flip the disc (only one disc)
Display_1x3(module_number, newDiscArray[0], newDiscArray[1], newDiscArray[2]);
// Clear all outputs of the controllers built into the displays
ClearAllOutputs();
}
/*----------------------------------------------------------------------------------*
* The function allows you to control 1x3 display. *
* We can control one, two or three discs of the selected display at a time. *
* The first argument is the relative number of the display in the series *
* of all displays. For example, if we have a combination of D1X3, D7SEG, D1X3, *
* then the second D1X3 display will have a relative number of 2 even though there *
* is a D7SEG display between the D1X3 displays. *
* -> module_number - relative number of the "D1X3" display *
* -> disc1, disc2, disc3. *
* *
* Brief: *
* The display consists 3 discs. *
* To flip a selected disc, we need to know the corresponding control outputs. *
* The list of information about control outputs for corresponding discs *
* to be displayed are contained in two tables: *
* -> setDisc_1x3[] - "1" *
* -> resetDisc_1x3[] - "0" *
*----------------------------------------------------------------------------------*/
void FlipDisc::Display_1x3(uint8_t module_number, uint8_t disc1 /* = 0xFF */, uint8_t disc2 /* = 0xFF */, uint8_t disc3 /* = 0xFF */)
{
/*
* Simple protection from user error.
* If the selected display has not been declared in Init() then the function will not execute.
*/
if(Fuse(module_number, D1X3) == true) return;
// Saving a list of disc statuses to the array
uint8_t newDiscArray[3]= {disc1, disc2, disc3};
// 3 discs - 3 loops
for(int disc = 0; disc < 3; disc++)
{
// Check if we have new data for disc. 0xFF - no data
if(newDiscArray[disc] != 0xFF)
{
// Start of SPI data transfer
digitalWrite(_EN_PIN, LOW);
/*
* Send blank data "0" to all control outputs of the other displays BEFORE
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D1X3, BEFORE);
/*
* Each of the discs has two sides, one side corresponds to the disk status "1" - color,
* the other side "0" - black.
* Each of the "0" or "1" statuses requires a different polarity of the current pulse
* released into the disc, and thus for each of the statuses we must drive different
* controller outputs to achieve the desired effect.
* The list of information about the statuses of all discs for the display
* and the currently selected dot to be displayed is contained in two tables:
* -> setDisc_1x3[] - "1"
* -> resetDisc_1x3[] - "0"
* Each separate display disc requires 1 byte of data to be transferred.
* To flip all 3 discs, we need to send 3 bytes of data.
*/
if(newDiscArray[disc] == 1) SPI.transfer(pgm_read_byte(&setDiscArray_1x3[disc]));
if(newDiscArray[disc] == 0) SPI.transfer(pgm_read_byte(&resetDiscArray_1x3[disc]));
/*
* Send blank data "0" to all control outputs of the other displays AFTER
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D1X3, AFTER);
// End of SPI data transfer
digitalWrite(_EN_PIN, HIGH);
// Release of 1ms current pulse
ReleaseCurrentPulse();
}
}
// Clear all outputs of the controllers built into the displays
ClearAllOutputs();
}
/*----------------------------------------------------------------------------------*
* Function allows you to control a selected disc in a 1x7 display. *
* We can control only one disc of the selected display at a time. The first *
* argument module_number is the relative number of the display in the series *
* of all displays. For example, if we have a combination of D1X7, D7SEG, D1X7, *
* then the second D1X7 display will have a relative number of 2 even though there *
* is a D7SEG display between the D1X7 displays. *
* -> module_number - relative number of the "D1X7" display *
* -> disc_number - display disc number counting from left to right 1-7 *
* -> disc_status - reset disc "0" or set disc "1" *
*----------------------------------------------------------------------------------*/
void FlipDisc::Disc_1x7(uint8_t module_number, uint8_t disc_number, bool disc_status)
{
/*
* Simple protection from user error.
* If the selected display has not been declared in Init() then the function will not execute.
*/
if(Fuse(module_number, D1X7) == true) return;
uint8_t newDiscArray[7];
/*
* disc_number - counting from left to right 1, 2,...7
* The array row numbers newDiscArray[] start at 0 so we need to subtract 1 (i-1)
* If we assign the value 0xFF to discs, the Display_1x7() function will ignore these discs
*/
for(int i = 1; i <= 7; i++)
{
if(disc_number == i) newDiscArray[i-1] = disc_status;
else newDiscArray[i-1] = 0xFF;
}
// Call the function to flip the disc (only one disc)
Display_1x7(module_number, newDiscArray[0], newDiscArray[1], newDiscArray[2],
newDiscArray[3], newDiscArray[4], newDiscArray[5], newDiscArray[6]);
// Clear all outputs of the controllers built into the displays
ClearAllOutputs();
}
/*----------------------------------------------------------------------------------*
* The function allows you to control 1x7 display. *
* We can control 7 discs of the selected display at a time. *
* The first argument is the relative number of the display in the series *
* of all displays. For example, if we have a combination of D1X7, D7SEG, D1X7, *
* then the second D1X7 display will have a relative number of 2 even though there *
* is a D7SEG display between the D1X7 displays. *
* -> module_number - relative number of the "D1X7" display *
* -> disc1, disc2, disc3, disc4, disc5, disc6, disc7. *
* *
* Brief: *
* The display consists 7 discs. *
* To flip a selected disc, we need to know the corresponding control outputs. *
* The list of information about control outputs for corresponding discs *
* to be displayed are contained in two tables: *
* -> setDiscArray_1x7[] - "1" *
* -> resetDiscArray_1x7[] - "0" *
*----------------------------------------------------------------------------------*/
void FlipDisc::Display_1x7(uint8_t module_number, uint8_t disc1 /* = 0xFF */, uint8_t disc2 /* = 0xFF */, uint8_t disc3 /* = 0xFF */,
uint8_t disc4 /* = 0xFF */, uint8_t disc5 /* = 0xFF */, uint8_t disc6 /* = 0xFF */, uint8_t disc7 /* = 0xFF */)
{
/*
* Simple protection from user error.
* If the selected display has not been declared in Init() then the function will not execute.
*/
if(Fuse(module_number, D1X7) == true) return;
// Saving a list of disc statuses to the array
uint8_t newDiscArray[7] = {disc1, disc2, disc3, disc4, disc5, disc6, disc7};
// 7 discs - 7 loops
for(int disc = 0; disc < 7; disc++)
{
// Check if we have new data for disc. 0xFF - no data
if(newDiscArray[disc] != 0xFF)
{
// Start of SPI data transfer
digitalWrite(_EN_PIN, LOW);
/*
* Send blank data "0" to all control outputs of the other displays BEFORE
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D1X7, BEFORE);
/*
* Each of the discs has two sides, one side corresponds to the disk status "1" - color,
* the other side "0" - black.
* Each of the "0" or "1" statuses requires a different polarity of the current pulse
* released into the disc, and thus for each of the statuses we must drive different
* controller outputs to achieve the desired effect.
* The list of information about the statuses of all discs for the display
* and the currently selected dot to be displayed is contained in two tables:
* -> setDiscArray_1x7[] - "1"
* -> resetDiscArray_1x7[] - "0"
* Each separate display disc requires 2 byte of data to be transferred.
* To flip all 7 discs, we need to send 14 bytes of data.
*/
for(int byte_number = 0; byte_number < 2; byte_number++)
{
if(newDiscArray[disc] == 1) SPI.transfer(pgm_read_byte(&setDiscArray_1x7[disc][byte_number]));
if(newDiscArray[disc] == 0) SPI.transfer(pgm_read_byte(&resetDiscArray_1x7[disc][byte_number]));
}
/*
* Send blank data "0" to all control outputs of the other displays AFTER
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D1X7, AFTER);
// End of SPI data transfer
digitalWrite(_EN_PIN, HIGH);
// Release of 1ms current pulse
ReleaseCurrentPulse();
}
}
// Clear all outputs of the controllers built into the displays
ClearAllOutputs();
}
/*----------------------------------------------------------------------------------*
* Function allows you to control a selected disc in a 2x6 display. *
* We can control only one disc of the selected display at a time. The first *
* argument module_number is the relative number of the display in the series *
* of all displays. For example, if we have a combination of D2X6, D7SEG, D2X6, *
* then the second D2X6 display will have a relative number of 2 even though there *
* is a D7SEG display between the D2X6 displays. *
* -> module_number - relative number of the "D2X6" display *
* -> disc_number - display disc number counting from right to left in each row *
* first row 1-6, second row 7-12 *
* -> disc_status - reset disc "0" or set disc "1" *
* 12 11 10 9 8 7 *
* 6 5 4 3 2 1 *
*----------------------------------------------------------------------------------*/
void FlipDisc::Disc_2x6(uint8_t module_number, uint8_t disc_number, bool disc_status)
{
/*
* Simple protection from user error.
* If the selected display has not been declared in Init() then the function will not execute.
*/
if(Fuse(module_number, D2X6) == true) return;
disc_number = disc_number - 1;
// Start of SPI data transfer
digitalWrite(_EN_PIN, LOW);
/*
* Send blank data "0" to all control outputs of the other displays BEFORE
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D2X6, BEFORE);
/*
* Each of the discs has two sides, one side corresponds to the disk status "1" - color,
* the other side "0" - black.
* Each of the "0" or "1" statuses requires a different polarity of the current pulse
* released into the disc, and thus for each of the statuses we must drive different
* controller outputs to achieve the desired effect.
* The list of information about the statuses of all discs for the display
* and the currently selected dot to be displayed is contained in two tables:
* -> setDiscArray_2x6[] - "1"
* -> resetDiscArray_2x6[] - "0"
* Each separate display disc requires 2 byte of data to be transferred.
* To flip all 12 discs, we need to send 24 bytes of data.
*/
for(int byte_number = 0; byte_number < 2; byte_number++)
{
if(disc_status == 1) SPI.transfer(pgm_read_byte(&setDiscArray_2x6[disc_number][byte_number]));
if(disc_status == 0) SPI.transfer(pgm_read_byte(&resetDiscArray_2x6[disc_number][byte_number]));
}
/*
* Send blank data "0" to all control outputs of the other displays AFTER
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D2X6, AFTER);
// End of SPI data transfer
digitalWrite(_EN_PIN, HIGH);
// Release of 1ms current pulse
ReleaseCurrentPulse();
// Clear all outputs of the controllers built into the displays
ClearAllOutputs();
}
/*----------------------------------------------------------------------------------*
* Function allows you to control a selected disc in a 2x6 display. *
* We can control only one disc of the selected display at a time. *
* Addressing selected disc using rows and columns. *
* The first argument module_number is the relative number of the display *
* in the series of all displays. For example, if we have a combination *
* of D2X6, D7SEG, D2X6, then the second D2X6 display will have a relative number *
* of 2 even though there is a D7SEG display between the D2X6 displays *
* -> module_number - relative number of the "D2X6" display *
* -> row_number - display disc row number counting from bottom to top 1-2 *
* -> column_number - display disc number counting from right to left 1-6 *
* -> disc_status - reset disc "0" or set disc "1" *
* *
* Rows, columns & discs numbers *
* 6 5 4 3 2 1 *
* 12 11 10 9 8 7 *
* 6 5 4 3 2 1 *
*----------------------------------------------------------------------------------*/
void FlipDisc::Display_2x6(uint8_t module_number, uint8_t row_number, uint8_t column_number, bool disc_status)
{
// Based on the row (1-2) and column (1-6) disc address, we determine the disc number 1-12
uint8_t disc_number = (row_number - 1) * 6 + column_number;
Disc_2x6(module_number, disc_number, disc_status);
}
/*----------------------------------------------------------------------------------*
* Function allows you to control a selected disc in a 3x3 display. *
* We can control only one disc of the selected display at a time. The first *
* argument module_number is the relative number of the display in the series *
* of all displays. For example, if we have a combination of D3X3, D7SEG, D3X3, *
* then the second D3X3 display will have a relative number of 2 even though there *
* is a D7SEG display between the D3X3 displays. *
* -> module_number - relative number of the "D3X3" display *
* -> disc_number - display disc number counting from left to right in each row *
* first row 1-3, second row 4-6, third row 7-9 *
* -> disc_status - reset disc "0" or set disc "1" *
* 7 8 9 *
* 4 5 6 *
* 1 2 3 *
*----------------------------------------------------------------------------------*/
void FlipDisc::Disc_3x3(uint8_t module_number, uint8_t disc_number, bool disc_status)
{
/*
* Simple protection from user error.
* If the selected display has not been declared in Init() then the function will not execute.
*/
if(Fuse(module_number, D3X3) == true) return;
disc_number = disc_number - 1;
// Start of SPI data transfer
digitalWrite(_EN_PIN, LOW);
/*
* Send blank data "0" to all control outputs of the other displays BEFORE
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D3X3, BEFORE);
/*
* Each of the discs has two sides, one side corresponds to the disk status "1" - color,
* the other side "0" - black.
* Each of the "0" or "1" statuses requires a different polarity of the current pulse
* released into the disc, and thus for each of the statuses we must drive different
* controller outputs to achieve the desired effect.
* The list of information about the statuses of all discs for the display
* and the currently selected dot to be displayed is contained in two tables:
* -> setDiscArray_3x3[] - "1"
* -> resetDiscArray_3x3[] - "0"
* Each separate display disc requires 2 byte of data to be transferred.
* To flip all 9 discs, we need to send 18 bytes of data.
*/
for(int byte_number = 0; byte_number < 2; byte_number++)
{
if(disc_status == 1) SPI.transfer(pgm_read_byte(&setDiscArray_3x3[disc_number][byte_number]));
if(disc_status == 0) SPI.transfer(pgm_read_byte(&resetDiscArray_3x3[disc_number][byte_number]));
}
/*
* Send blank data "0" to all control outputs of the other displays AFTER
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D3X3, AFTER);
// End of SPI data transfer
digitalWrite(_EN_PIN, HIGH);
// Release of 1ms current pulse
ReleaseCurrentPulse();
// Clear all outputs of the controllers built into the displays
ClearAllOutputs();
}
/*----------------------------------------------------------------------------------*
* Function allows you to control a selected disc in a 3x3 display. *
* We can control only one disc of the selected display at a time. *
* Addressing selected disc using rows and columns. *
* The first argument module_number is the relative number of the display *
* in the series of all displays. For example, if we have a combination *
* of D3X3, D7SEG, D3X3, then the second D3X3 display will have a relative number *
* of 2 even though there is a D7SEG display between the D3X3 displays *
* -> module_number - relative number of the "D3X3" display *
* -> row_number - display disc row number counting from bottom to top 1-3 *
* -> column_number - display disc number counting from left to right 1-3 *
* -> disc_status - reset disc "0" or set disc "1" *
* *
* Rows, columns & discs numbers *
* 1 2 3 *
* 3 7 8 9 *
* 2 4 5 6 *
* 1 1 2 3 *
*----------------------------------------------------------------------------------*/
void FlipDisc::Display_3x3(uint8_t module_number, uint8_t row_number, uint8_t column_number, bool disc_status)
{
// Based on the row (1-3) and column (1-3) disc address, we determine the disc number 1-9
uint8_t disc_number = (row_number - 1) * 3 + column_number;
Disc_3x3(module_number, disc_number, disc_status);
}
/*----------------------------------------------------------------------------------*
* Function allows you to control a selected disc in a 3x4 display. *
* We can control only one disc of the selected display at a time. The first *
* argument module_number is the relative number of the display in the series *
* of all displays. For example, if we have a combination of D3X4, D7SEG, D3X4, *
* then the second D3X4 display will have a relative number of 2 even though there *
* is a D7SEG display between the D3X4 displays. *
* -> module_number - relative number of the "D3X4" display *
* -> disc_number - display disc number counting from left to right in each row *
* first row 1-3, second row 4-6, third row 7-9, four row 10-12 *
* -> disc_status - reset disc "0" or set disc "1" *
* 10 11 12 *
* 7 8 9 *
* 4 5 6 *
* 1 2 3 *
*----------------------------------------------------------------------------------*/
void FlipDisc::Disc_3x4(uint8_t module_number, uint8_t disc_number, bool disc_status)
{
/*
* Simple protection from user error.
* If the selected display has not been declared in Init() then the function will not execute.
*/
if(Fuse(module_number, D3X4) == true) return;
disc_number = disc_number - 1;
// Start of SPI data transfer
digitalWrite(_EN_PIN, LOW);
/*
* Send blank data "0" to all control outputs of the other displays BEFORE
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D3X4, BEFORE);
/*
* Each of the discs has two sides, one side corresponds to the disk status "1" - color,
* the other side "0" - black.
* Each of the "0" or "1" statuses requires a different polarity of the current pulse
* released into the disc, and thus for each of the statuses we must drive different
* controller outputs to achieve the desired effect.
* The list of information about the statuses of all discs for the display
* and the currently selected dot to be displayed is contained in two tables:
* -> setDiscArray_3x4[] - "1"
* -> resetDiscArray_3x4[] - "0"
* Each separate display disc requires 2 byte of data to be transferred.
* To flip all 7 discs, we need to send 14 bytes of data.
*/
for(int byte_number = 0; byte_number < 2; byte_number++)
{
if(disc_status == 1) SPI.transfer(pgm_read_byte(&setDiscArray_3x4[disc_number][byte_number]));
if(disc_status == 0) SPI.transfer(pgm_read_byte(&resetDiscArray_3x4[disc_number][byte_number]));
}
/*
* Send blank data "0" to all control outputs of the other displays AFTER
* sending control data to the selected display.
* Detailed information in the function description SendBlankData().
*/
SendBlankData(module_number, D3X4, AFTER);
// End of SPI data transfer
digitalWrite(_EN_PIN, HIGH);
// Release of 1ms current pulse
ReleaseCurrentPulse();
// Clear all outputs of the controllers built into the displays
ClearAllOutputs();
}