-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharduinocode.pde
More file actions
134 lines (127 loc) · 2.75 KB
/
arduinocode.pde
File metadata and controls
134 lines (127 loc) · 2.75 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
//LED Cube 5x5x5 - Arduino sketch
//Columns Shift Register
int latchPinC = 5;
int clockPinC = 4;
int dataPinC = 3;
//Rows Shift Register
int latchPinR = 10;
int clockPinR = 11;
int dataPinR = 9;
byte matrix[26];
byte matconv[25][5];
long matout[4][5];
byte head;
int state = 0;
void matconvert() {
for(int row = 0; row < 25; row++) {
for(int col = 0; col <5; col++) {
matconv[row][col] = bitRead( matrix[row], col) ;
}
}
for(int col = 0; col < 5; col++) {
for(int row = 0; row < 24; row++) {
for(int r = 0; r < 3; r++) {
matout[r][col] = bitWrite( matout[r][col], row - (8 * r), matconv[row][col]);
}
matout[3][col] = bitWrite( matout[3][col], 0, matconv[24][col]);
}
}
panelOut();
}
void panelOut() {
for (int col = 0; col < 5; col++) {
int colbit = 1 << col;
digitalWrite(latchPinC, LOW);
shiftOut(dataPinC, clockPinC, MSBFIRST, colbit);
digitalWrite(latchPinR, LOW);
shiftOut(dataPinR, clockPinR, MSBFIRST, matout[3][col]);
shiftOut(dataPinR, clockPinR, MSBFIRST, matout[2][col]);
shiftOut(dataPinR, clockPinR, MSBFIRST, matout[1][col]);
shiftOut(dataPinR, clockPinR, MSBFIRST, matout[0][col]);
digitalWrite(latchPinC, HIGH);
digitalWrite(latchPinR, HIGH);
}
}
void setup() {
for(int row = 0; row < 2; row++) {
for(int col = 0; col < 8; col++) {
matout[row][col] = 0;
}
}
pinMode(clockPinC, OUTPUT);
pinMode(latchPinC, OUTPUT);
pinMode(dataPinC, OUTPUT);
pinMode(clockPinR, OUTPUT);
pinMode(latchPinR, OUTPUT);
pinMode(dataPinR, OUTPUT);
digitalWrite(clockPinC, LOW);
digitalWrite(latchPinC, LOW);
digitalWrite(dataPinC, LOW);
digitalWrite(clockPinR, LOW);
digitalWrite(latchPinR, LOW);
digitalWrite(dataPinR, LOW);
Serial.begin(9600);
head = (byte) 0x55;
}
void loop() {
if (Serial.available()>0) {
int input = Serial.read();
switch (state) {
case 0:
if (input==head) {
state = 1;
}
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
if((byte) input < 0) {
matrix[state-1] = (byte) input + 256;
state++;
break;
}
else {
matrix[state-1] = (byte) input;
state++;
break;
}
case 25:
if((byte) input < 0) {
matrix[state-1] = (byte) input + 256;
state = 0;
matconvert();
break;
}
else {
matrix[state-1] = (byte) input;
state = 0;
matconvert();
break;
}
}
}
else {
panelOut();
}
}