-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLED_Matrix_V0.2.ino
177 lines (159 loc) · 6.11 KB
/
LED_Matrix_V0.2.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
#define DS_pin1 7 //for columns (anode)
#define SH_CP_pin1 5
#define ST_CP_pin1 6
#define DS_pin2 4 //for rows (cathode)
#define SH_CP_pin2 13
#define ST_CP_pin2 3
unsigned int a[16] = {0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100, 0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001};
//values for a single column at a time, starting from the leftmost column to the rightmost column
void shift_resistor_receive_data(int data1, int data2){
for (int i = 0; i < 16; i++){
if ( data1 & 0b00000000000000001){
digitalWrite(DS_pin1, HIGH);
}
else{
digitalWrite(DS_pin1, LOW);
}
data1 = data1 >> 1;
digitalWrite(SH_CP_pin1, HIGH);
digitalWrite(SH_CP_pin1, LOW);
}
digitalWrite(ST_CP_pin1, HIGH);
digitalWrite(ST_CP_pin1, LOW);
for (int i = 0; i < 16; i++){
if ( data2 & 0b1000000000000000){
digitalWrite(DS_pin2, HIGH);
}
else{
digitalWrite(DS_pin2, LOW);
}
data2 = data2 << 1;
digitalWrite(SH_CP_pin2, HIGH);
digitalWrite(SH_CP_pin2, LOW);
}
digitalWrite(ST_CP_pin2, HIGH);
digitalWrite(ST_CP_pin2, LOW);
}
void print_array(bool shape[16][16]){
for (int j = 0; j < 16; j++){
unsigned int value = 0;
unsigned int temp = 1;
for (int i = 0; i < 16; i++){
if (i != 0)
temp = temp * 2;
value = value + int(shape[i][j]) * temp;
}
shift_resistor_receive_data(a[j], value); //constantly column is moving right and column wise data of the row is getting printed
delayMicroseconds(100); //a[j] value is for one column, and value data from the 2d array representing a single LED
shift_resistor_receive_data(0x0000, 0xFFFF); //clears whole matrix before the next data is displayed on the screen
}
}
void scroll_array(bool shape[16][16]){
for(int j=0; j<16; j++){
int value =0, temp=0;
for (int i = 0; i < 16; i++){
if (i != 0)
temp = temp * 2;
value = value + int(shape[i][j]) * temp;
}
shift_resistor_receive_data(a[j], value); //constantly column is moving right and column wise data of the row is getting printed
delayMicroseconds(100); //a[j] value is for one column, and value data from the 2d array representing a single LED
shift_resistor_receive_data(0x0000, 0xFFFF); //clears whole matrix before the next data is displayed on the screen
}
}
void LED_On(int ST_CP, int DS, int SH_CP, int value1, int value2){
digitalWrite(ST_CP, LOW);
shiftOut(DS, SH_CP, MSBFIRST, value1);
shiftOut(DS, SH_CP, MSBFIRST, value2);
digitalWrite(ST_CP, HIGH);
}
void shift_array(bool shape[16][16]){
int i, j,temp;
for(i=0; i<16; i++){
for(j=0; j<16; j++){
if(j==0){
shape[i][15]=shape[i][0];
}
if(shape[i][j] == 0){
temp = shape[i][j-1];
shape[i][j-1] = shape[i][j];
shape[i][j] = temp;
}
}
}
}
void setup() {
Serial.begin(9600);
pinMode(DS_pin1, OUTPUT);
pinMode(SH_CP_pin1, OUTPUT);
pinMode(ST_CP_pin1, OUTPUT);
pinMode(DS_pin2, OUTPUT);
pinMode(SH_CP_pin2, OUTPUT);
pinMode(ST_CP_pin2, OUTPUT);
shift_resistor_receive_data(0xFFFF, 0x0000); //lights all the LEDs to check which ones are defective ones
delay(100);
}
bool game[16][16]={
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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