This repository has been archived by the owner on Feb 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Matrix_Test.ino
229 lines (211 loc) · 6.19 KB
/
Matrix_Test.ino
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
#include "LedControl.h"
#define Width 16
#define Height 16
/*
* pin 12 is connected to the DATA
* pin 11 is connected to the CLK
* pin 10 is connected to CS
*/
LedControl lc=LedControl(12,11,10,4);
byte t1[16][16] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0},
{0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0},
{0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
unsigned long delayTime=500;
//byte t1[16][16];
byte t2[16][16];
byte last[16][16];
int idx=0;
int noOfGeneration = 0;
byte A[8][8];
/*
byte A[8][8] = {{1, 0, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 1, 1, 0},
{0, 0, 1, 0, 0, 1, 1, 0},
{0, 0, 0, 1, 1, 0, 0, 0}};
*/
void setup() {
Serial.begin(9600);
//we have already set the number of devices when we created the LedControl
int devices=lc.getDeviceCount();
//we have to init all devices in a loop
for(int address=0;address<devices;address++) {
delay(10);
/*The MAX72XX is in power-saving mode on startup*/
lc.shutdown(address,false);
/* Set the brightness to a medium values */
lc.setIntensity(address,1);
/* and clear the display */
lc.clearDisplay(address);
}
//randomize(t1);
}
void loop() {
display(t1);
shiftUp();
//fadeDisplay();
waitForKeyPress();
delay(delayTime);
}
void shiftUp() {
for (int i=0; i<16;i++) {
for (int j=0; j<16; j++) {
t2[i][j]=t1[i][j];
Serial.print(t2[i][j]);
Serial.print(" ");
}
Serial.println();
}
for (int i=0; i<16; i++) {
t1[15][i]=t2[0][i];
}
for (int i=0; i<15;i++) {
for (int j=0; j<16; j++) {
t1[i][j]=t2[i+1][j];
}
}
}
void fadeDisplay() {
unsigned char delayInterval = 50;
int devices=lc.getDeviceCount();
for (int brightness = 0; brightness<16; brightness++) {
for(int address=0;address<devices;address++) {
lc.setIntensity(address,brightness);
delay(delayInterval);
}
delay(delayInterval);
}
for (int brightness = 15; brightness>=0; brightness--) {
for(int address=0;address<devices;address++) {
lc.setIntensity(address,brightness);
delay(delayInterval);
}
delay(delayInterval);
}
for (int address=0; address<4; address++) {
lc.clearDisplay(address);
delay(delayInterval);
}
}
void display(byte t1[16][16]) {
for(unsigned char matrixCount = 0; matrixCount < 4; matrixCount++) {
lc.clearDisplay(matrixCount);
for (unsigned int i=0; i<8;i++) {
for (unsigned int j=0; j<8; j++) {
switch (matrixCount) {
case 1: {
A[i][j] = t1[i][j];
/* Serial.print(i);
Serial.print(" ");
Serial.print(j);
Serial.print(" ");
Serial.println(A[i][j]);
*/ break;
}
case 0: {
A[i][j] = t1[i][j+8];
/* Serial.print(i);
Serial.print(" ");
Serial.print(j+8);
Serial.print(" ");
Serial.println(A[i][j]);
*/ break;
}
case 2: {
A[i][j] = t1[i+8][j];
/* Serial.print(i+8);
Serial.print(" ");
Serial.print(j);
Serial.print(" ");
Serial.println(A[i][j]);
*/ break;
}
case 3: {
A[i][j] = t1[i+8][j+8];
/* Serial.print(i+8);
Serial.print(" ");
Serial.print(j+8);
Serial.print(" ");
Serial.println(A[i][j]);
*/ break;
}
}
Serial.print(A[i][j]);
Serial.print(" ");
}
Serial.println();
}
Serial.print("matrixCount: ");
Serial.println(matrixCount);
//waitForKeyPress();
//delay(delayTime*5);
updateDisplay(matrixCount);
}
}
void waitForKeyPress() {
Serial.println("Press enter");
while (1) {
int serialData = Serial.read();
if (serialData == '\r' ) {
break;
}
}
}
void updateDisplay(unsigned char address) {
if (address <2 ) {
for (int i=0; i<8; i++) {
lc.setRow(address,i,rowValue(address,i));
//delay(100);
}
} else {
for (int i=0; i<8; i++) {
lc.setRow(address,i,rowValue(address,7-i));
//delay(100);
}
}
}
int rowValue(unsigned char address, byte i) {
int result;
switch (address) {
case 0: {
result = (A[i][0]*128) + (A[i][1]*64) + (A[i][2]*32) + (A[i][3]*16) + (A[i][4]*8) + (A[i][5]*4) + (A[i][6]*2) + (A[i][7]*1);
break;
}
case 1: {
result = (A[i][0]*128) + (A[i][1]*64) + (A[i][2]*32) + (A[i][3]*16) + (A[i][4]*8) + (A[i][5]*4) + (A[i][6]*2) + (A[i][7]*1);
break;
}
case 2: {
result = (A[i][7]*128) + (A[i][6]*64) + (A[i][5]*32) + (A[i][4]*16) + (A[i][3]*8) + (A[i][2]*4) + (A[i][1]*2) + (A[i][0]*1);
break;
}
case 3: {
result = (A[i][7]*128) + (A[i][6]*64) + (A[i][5]*32) + (A[i][4]*16) + (A[i][3]*8) + (A[i][2]*4) + (A[i][1]*2) + (A[i][0]*1);
break;
}
}
//Serial.println();
//Serial.print(result);
//Serial.println();
//Serial.print(" ");
//Serial.print(i);
//Serial.print(" ");
//Serial.println(result);
return result;
}