-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathequalizer.ino
101 lines (64 loc) · 1.96 KB
/
equalizer.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
#include "arduinoFFT.h"
#include <Adafruit_NeoPixel.h>
#define LedCount 256
#define PIN_LED D1
#define PIN_ANALOG A0
#define PIN_RESET D6
#define PIN_STROBE D7
#define SAMPLES 32 //Must be a power of 2
#define SAMPLING_FREQUENCY 1000 //Hz, must be less than 10000 due to ADC
#define numVertical 16
#define numHorizontal 16
unsigned int sampling_period_us;
unsigned long microseconds;
double vReal[SAMPLES];
double vImag[SAMPLES];
float r, g, b, mapped;
int ledFullMatrix[ numVertical + 1 ][ numVertical + 1 ];
int caseId, rollId = 0, ledCursor = 0, finalCursor = 0;
arduinoFFT FFT = arduinoFFT();
Adafruit_NeoPixel strip(LedCount, PIN_LED, NEO_GRB + NEO_KHZ800);
void setup() {
createMatrix();
strip.begin();
strip.setBrightness(255);
strip.show();
pinMode(PIN_ANALOG, INPUT);
pinMode(PIN_STROBE, OUTPUT);
pinMode(PIN_RESET, OUTPUT);
digitalWrite(PIN_RESET, LOW);
digitalWrite(PIN_STROBE, HIGH);
}
void loop() {
equalizer();
strip.show();
}
void createMatrix() {
for ( int i = 1; i <= numVertical; i++ ) {
for ( int j = 1; j <= numHorizontal; j++ ) {
if ( i % 2 == 0 )
ledFullMatrix[ i ][ j ] = ( i * numVertical - numVertical ) + ( numVertical - j );
else
ledFullMatrix[ i ][ j ] = ( i * numHorizontal - numHorizontal ) + j - 1;
}
}
}
void equalizer() {
digitalWrite(PIN_RESET, HIGH);
digitalWrite(PIN_RESET, LOW);
for (int i = 0; i < 7; i++) {
digitalWrite(PIN_STROBE, LOW);
delayMicroseconds(40);
bands[i] = analogRead(0);
Serial.println( "Band " + (String) i + " ==> " + (String) bands[i] );
digitalWrite(PIN_STROBE, HIGH);
delayMicroseconds(40);
}
for (int i = 0; i < 7; i++) {
mapped = map( round( bands[i] ), 1000, 100, 0, 16);
for ( int j = 1; j <= mapped; j++ )
strip.setPixelColor( ledFullMatrix[j][i], 255, 255, 255, 0 );
for ( int k = 16; k > mapped; k-- )
strip.setPixelColor( ledFullMatrix[k][i], 0, 0, 0 );
}
}