-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaveform.pde
100 lines (84 loc) · 2.09 KB
/
waveform.pde
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
////////////////////////////////////////////////
// OTOH WAVEFORM
////////////////////////////////////////////////
// x => [0, 31]
// val => [0, 15]
void waveformFuncOn(int x, byte val) {
if(x > 15) {
if(x < 24) {
x += 8;
}
else {
x -= 8;
}
}
int waveformMaxNum = x / 16;
int reg, col;
x %= 16;
if(x < 8) {
reg = -1 * ((x % 8) - 7);
}
else {
reg = x % 8;
}
int colConversionOffset = 0;
if(x < 8) {
if(0 == waveformMaxNum) {
colConversionOffset = 4;
}
}
else {
if(0 != waveformMaxNum) {
colConversionOffset = 4;
}
}
int resetValue = 0;
for(int i = 0; i < 4; i++) {
resetValue += waveformColConversion[i+colConversionOffset];
}
waveformRegValue[waveformMaxNum][reg] ^= waveformRegValue[waveformMaxNum][reg] & resetValue;
for(int i = 0; i < 4; i++) {
if((val >> i) & 1) {
waveformRegValue[waveformMaxNum][reg] ^= waveformColConversion[i+colConversionOffset];
}
}
if(debug) {
Serial.print("\n");
Serial.print(x);
Serial.print(", ");
Serial.print(waveformMaxNum);
Serial.print(", ");
Serial.print(waveformRegConversion[reg]);
Serial.print(", ");
Serial.print(waveformRegValue[waveformMaxNum][reg]);
}
maxim.one(waveformMax[waveformMaxNum], waveformRegConversion[reg], waveformRegValue[waveformMaxNum][reg]);
}
void waveformReset() {
for(int i = 0; i < 2; i++) {
for(int reg = 0; reg < 8; reg++) {
waveformRegValue[i][reg] = 0;
maxim.one(waveformMax[i], waveformRegConversion[reg], 0);
}
}
}
void waveform() {
for(int i = 0; i < 32; i++) {
// waveformFuncOn(i, cuorizini[i]);
waveformFuncOn(i, otohWF[i]);
// waveformFuncOn(i, wave[i]);
// waveformFuncOn(i, squares[i]);
// waveformFuncOn(i, triangles[i]);
delay(vel);
}
}
void waveformCallback(byte argc, byte *argv) {
// argv[0] --> [1..32] --> waveform reg [0,31]
int reg = argv[0] - 1;
// argv[0] --> [1..16] --> waveform col [0,15]
byte col = argv[1] - 1;
waveformFuncOn(reg,col);
}
void waveformClearCallback() {
waveformReset();
}