-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulbWall.ino
399 lines (381 loc) · 9.39 KB
/
bulbWall.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
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
#include <Wire.h>
#include "Adafruit_MCP23017.h"
#include "arduinoFFT.h"
#define RELAY 0
Adafruit_MCP23017 mcp1;
Adafruit_MCP23017 mcp2;
Adafruit_MCP23017 mcp3;
Adafruit_MCP23017 mcp4;
arduinoFFT FFT = arduinoFFT();
//void offAbove(int col,int val);
//void onBelow(int col,int val);
void cercle1(bool state);
void cercle2(bool state);
void cercle3(bool state);
void cercle4(bool state);
void cercle5(bool state);
void cercle6(bool state);
void cercle7(bool state);
void cercle8(bool state);
void cercle9(bool state);
void cercle10(bool state);
///*
//These values can be changed in order to evaluate the functions
//*/
//const uint16_t samples = 64; //This value MUST ALWAYS be a power of 2
//const double signalFrequency = 1000;
//const double samplingFrequency = 5000;
//const uint8_t amplitude = 100;
///*
//These are the input and output vectors
//Input vectors receive computed results from FFT
//*/
//double vReal[samples];
//double vImag[samples];
//
//#define SCL_INDEX 0x00
//#define SCL_TIME 0x01
//#define SCL_FREQUENCY 0x02
//#define SCL_PLOT 0x03
void setup() {
mcp1.begin(7); // use default address 0
mcp1.pinMode(0, OUTPUT);//do not turn on all the pins in one command, it can draw too much current in the port expander
mcp1.pinMode(1, OUTPUT);
mcp1.pinMode(2, OUTPUT);
mcp1.pinMode(3, OUTPUT);
mcp1.pinMode(4, OUTPUT);
mcp1.pinMode(5, OUTPUT);
mcp1.pinMode(6, OUTPUT);
mcp1.pinMode(7, OUTPUT);
mcp1.pinMode(8, OUTPUT);
mcp1.pinMode(9, OUTPUT);
mcp1.pinMode(10, OUTPUT);
mcp1.pinMode(11, OUTPUT);
mcp1.pinMode(12, OUTPUT);
mcp1.pinMode(13, OUTPUT);
mcp1.pinMode(14, OUTPUT);
mcp1.pinMode(15, OUTPUT);
mcp2.begin(6); // use default address 0
mcp2.pinMode(0, OUTPUT);
mcp2.pinMode(1, OUTPUT);
mcp2.pinMode(2, OUTPUT);
mcp2.pinMode(3, OUTPUT);
mcp2.pinMode(4, OUTPUT);
mcp2.pinMode(5, OUTPUT);
mcp2.pinMode(6, OUTPUT);
mcp2.pinMode(7, OUTPUT);
mcp2.pinMode(8, OUTPUT);
mcp2.pinMode(9, OUTPUT);
mcp2.pinMode(10, OUTPUT);
mcp2.pinMode(11, OUTPUT);
mcp2.pinMode(12, OUTPUT);
mcp2.pinMode(13, OUTPUT);
mcp2.pinMode(14, OUTPUT);
mcp2.pinMode(15, OUTPUT);
mcp3.begin(0); // use default address 0
mcp3.pinMode(0, OUTPUT);
mcp3.pinMode(1, OUTPUT);
mcp3.pinMode(2, OUTPUT);
mcp3.pinMode(3, OUTPUT);
mcp3.pinMode(4, OUTPUT);
mcp3.pinMode(5, OUTPUT);
mcp3.pinMode(6, OUTPUT);
mcp3.pinMode(7, OUTPUT);
mcp3.pinMode(8, OUTPUT);
mcp3.pinMode(9, OUTPUT);
mcp3.pinMode(10, OUTPUT);
mcp3.pinMode(11, OUTPUT);
mcp3.pinMode(12, OUTPUT);
mcp3.pinMode(13, OUTPUT);
mcp3.pinMode(14, OUTPUT);
mcp3.pinMode(15, OUTPUT);
mcp4.begin(4); // use default address 0
mcp4.pinMode(0, OUTPUT);
mcp4.pinMode(1, OUTPUT);
mcp4.pinMode(2, OUTPUT);
mcp4.pinMode(3, OUTPUT);
mcp4.pinMode(4, OUTPUT);
mcp4.pinMode(5, OUTPUT);
mcp4.pinMode(6, OUTPUT);
mcp4.pinMode(7, OUTPUT);
mcp4.pinMode(8, OUTPUT);
mcp4.pinMode(9, OUTPUT);
mcp4.pinMode(10, OUTPUT);
mcp4.pinMode(11, OUTPUT);
mcp4.pinMode(12, OUTPUT);
mcp4.pinMode(13, OUTPUT);
mcp4.pinMode(14, OUTPUT);
mcp4.pinMode(15, OUTPUT);
// nitialize serial communication at 9600 bits per second:
//Serial.begin(9600);
pinMode(RELAY,OUTPUT); //pin 0 is the relay
digitalWrite(RELAY,HIGH);//turn on relay after port expanders set
//randomSeed(analogRead(0));
}
int micValue=0;
int micIntensity=0;
const unsigned long interval=50; //50ms -> 20Hz
//unsigned long sustain=200;
unsigned long previousMillis = 0;
int x=0,xactuel=0;
int maxSignal=0;
int count=0;
void loop() {
unsigned long currentMillis = millis();
micValue = analogRead(A5);//microphone
micIntensity=abs(micValue-520);
if(micIntensity > maxSignal){
maxSignal=micIntensity;
}
//Serial.println(intensity);
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
//turn off the old one
// mcp1.digitalWrite(15-x,LOW);
// mcp1.digitalWrite(x1,LOW);
// mcp2.digitalWrite(15-x2,LOW);
// mcp2.digitalWrite(x3,LOW);
// mcp3.digitalWrite(15-x4,LOW);
// mcp3.digitalWrite(x5,LOW);
// mcp4.digitalWrite(15-x4,LOW);
// mcp4.digitalWrite(x5,LOW);
////////////////////////////////////////////////////
xactuel=x;
x=map(maxSignal,0,512,0,10);
int i=0;
if(x > xactuel){
for(i=xactuel;i<=x;++i){
switch (i){
case 1:
cercle1(HIGH);
break;
case 2:
cercle2(HIGH);
break;
case 3:
cercle3(HIGH);
break;
case 4:
cercle4(HIGH);
break;
case 5:
cercle5(HIGH);
break;
case 6:
cercle6(HIGH);
break;
case 7:
cercle7(HIGH);
break;
case 8:
cercle8(HIGH);
break;
case 9:
cercle9(HIGH);
break;
case 10:
cercle10(HIGH);
break;
}
}
}
else if(x < xactuel){
for(i=xactuel;i>=x;--i){
switch (i){
case 1:
cercle1(LOW);
break;
case 2:
cercle2(LOW);
break;
case 3:
cercle3(LOW);
break;
case 4:
cercle4(LOW);
break;
case 5:
cercle5(LOW);
break;
case 6:
cercle6(LOW);
break;
case 7:
cercle7(LOW);
break;
case 8:
cercle8(LOW);
break;
case 9:
cercle9(LOW);
break;
case 10:
cercle10(LOW);
break;
}
}
}
else{
}
//turn on new ones
// mcp1.digitalWrite(15-x,HIGH);
// mcp1.digitalWrite(x1,HIGH);
// mcp2.digitalWrite(15-x2,HIGH);
// mcp2.digitalWrite(x3,HIGH);
// mcp3.digitalWrite(15-x4,HIGH);
// mcp3.digitalWrite(x5,HIGH);
// mcp4.digitalWrite(15-x4,HIGH);
// mcp4.digitalWrite(x5,HIGH);
maxSignal=0;//reset for new period
}
}
//void offAbove(int col, int val){
// int i=0;
// if(col==1){
// for(i=val+1;i<16;++i){
// mcp1.digitalWrite(15-i,LOW);
// }
// }
// if(col==2){
// for(i=val+1;i<16;++i){
// mcp1.digitalWrite(i,LOW);
// }
// }
// if(col==3){
// for(i=val+1;i<16;++i){
// mcp2.digitalWrite(15-i,LOW);
// }
// }
// if(col==4){
// for(i=val+1;i<16;++i){
// mcp2.digitalWrite(i,LOW);
// }
// }
// if(col==5){
// for(i=val+1;i<16;++i){
// mcp3.digitalWrite(15-i,LOW);
// }
// }
// if(col==6){
// for(i=val+1;i<16;++i){
// mcp3.digitalWrite(i,LOW);
// }
// }
//}
//void onBelow(int col, int val){
// int i=0;
// if(col==1){
// for(i=val;i>=0;--i){
// mcp1.digitalWrite(15-i,HIGH);
// }
// }
// if(col==2){
// for(i=val;i>=0;--i){
// mcp1.digitalWrite(i,HIGH);
// }
// }
// if(col==3){
// for(i=val;i>=0;--i){
// mcp2.digitalWrite(15-i,HIGH);
// }
// }
// if(col==4){
// for(i=val;i>=0;--i){
// mcp2.digitalWrite(i,HIGH);
// }
// }
// if(col==5){
// for(i=val;i>=0;--i){
// mcp3.digitalWrite(15-i,HIGH);
// }
// }
// if(col==6){
// for(i=val;i>=0;--i){
// mcp3.digitalWrite(i,HIGH);
// }
// }
//}
void cercle1(bool state){
mcp2.digitalWrite(3,state);
mcp2.digitalWrite(4,state);
mcp3.digitalWrite(11,state);
mcp3.digitalWrite(12,state);
}
void cercle2(bool state){
mcp2.digitalWrite(11,state);
mcp2.digitalWrite(12,state);
mcp2.digitalWrite(2,state);
mcp2.digitalWrite(5,state);
mcp3.digitalWrite(13,state);
mcp3.digitalWrite(10,state);
mcp3.digitalWrite(4,state);
mcp3.digitalWrite(3,state);
}
void cercle3(bool state){
mcp2.digitalWrite(13,state);
mcp2.digitalWrite(10,state);
mcp3.digitalWrite(2,state);
mcp3.digitalWrite(5,state);
}
void cercle4(bool state){
mcp1.digitalWrite(3,state);
mcp1.digitalWrite(4,state);
mcp2.digitalWrite(1,state);
mcp2.digitalWrite(6,state);
mcp3.digitalWrite(14,state);
mcp3.digitalWrite(9,state);
mcp4.digitalWrite(11,state);
mcp4.digitalWrite(12,state);
}
void cercle5(bool state){
mcp1.digitalWrite(2,state);
mcp1.digitalWrite(5,state);
mcp2.digitalWrite(14,state);
mcp2.digitalWrite(9,state);
mcp3.digitalWrite(6,state);
mcp3.digitalWrite(1,state);
mcp4.digitalWrite(10,state);
mcp4.digitalWrite(13,state);
}
void cercle6(bool state){
mcp1.digitalWrite(1,state);
mcp1.digitalWrite(6,state);
mcp4.digitalWrite(14,state);
mcp4.digitalWrite(9,state);
}
void cercle7(bool state){
mcp1.digitalWrite(12,state);
mcp1.digitalWrite(11,state);
mcp2.digitalWrite(7,state);
mcp2.digitalWrite(0,state);
mcp3.digitalWrite(8,state);
mcp3.digitalWrite(15,state);
mcp4.digitalWrite(4,state);
mcp4.digitalWrite(3,state);
}
void cercle8(bool state){
mcp1.digitalWrite(10,state);
mcp1.digitalWrite(13,state);
mcp2.digitalWrite(8,state);
mcp2.digitalWrite(15,state);
mcp3.digitalWrite(7,state);
mcp3.digitalWrite(0,state);
mcp4.digitalWrite(5,state);
mcp4.digitalWrite(2,state);
}
void cercle9(bool state){
mcp1.digitalWrite(9,state);
mcp1.digitalWrite(14,state);
mcp1.digitalWrite(7,state);
mcp1.digitalWrite(0,state);
mcp4.digitalWrite(8,state);
mcp4.digitalWrite(15,state);
mcp4.digitalWrite(6,state);
mcp4.digitalWrite(1,state);
}
void cercle10(bool state){
mcp1.digitalWrite(8,state);
mcp1.digitalWrite(15,state);
mcp4.digitalWrite(7,state);
mcp4.digitalWrite(0,state);
}