-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRKG_14_BAND - kopie.ino_
221 lines (196 loc) · 5.76 KB
/
RKG_14_BAND - kopie.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
// Project: 14 Band Spectrum Analyzer using WS2812B/SK6812
// Target Platform: Arduino Mega2560 or Mega2560 PRO MINI
// The original code has been modified by PLATINUM to allow a scalable platform with many more bands.
// It is not possible to run modified code on a UNO,NANO or PRO MINI. due to memory limitations.
// The library Si5351mcu is being utilized for programming masterclock IC frequencies.
// Special thanks to Pavel Milanes for his outstanding work. https://github.com/pavelmc/Si5351mcu
// Analog reading of MSGEQ7 IC1 and IC2 use pin A0 and A1.
// Clock pin from MSGEQ7 IC1 and IC2 to Si5351mcu board clock 0 and 1
// Si5351mcu SCL and SDA use pin 20 and 21
// See the Schematic Diagram for more info
// Programmed and tested by PLATINUM
// Version 1.0
//***************************************************************************************************
#include <Adafruit_NeoPixel.h>
#include <si5351mcu.h> //Si5351mcu library
Si5351mcu Si; //Si5351mcu Board
#define PULSE_PIN 13
#define NOISE 50
#define ROWS 8 //num of row MAX=20
#define COLUMNS 14 //num of column
#define DATA_PIN D7 //9 //led data pin
#define STROBE_PIN D5 //6 //MSGEQ7 strobe pin
#define RESET_PIN D6 //7 //MSGEQ7 reset pin
#define BAND_SWITCH D3
#define NUMPIXELS ROWS * COLUMNS
//#define DEBUG
struct Point{
char x, y;
char r,g,b;
bool active;
};
struct TopPoint{
int position;
int peakpause;
};
Point spectrum[ROWS][COLUMNS];
TopPoint peakhold[COLUMNS];
int spectrumValue[COLUMNS];
long int counter = 0;
int long pwmpulse = 0;
bool toggle = false;
int long time_change = 0;
int effect = 0;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, DATA_PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
Serial.begin(115200L);
Si.init(25000000L);
Si.setFreq(0, 104570);
Si.setFreq(1, 166280);
Si.setPower(0, SIOUT_4mA);
Si.setPower(1, SIOUT_4mA);
Si.enable(0);
Si.enable(1);
pinMode (STROBE_PIN, OUTPUT);
pinMode (RESET_PIN, OUTPUT);
pinMode (DATA_PIN, OUTPUT);
pinMode (PULSE_PIN, OUTPUT);
pinMode (BAND_SWITCH, OUTPUT);
digitalWrite(PULSE_PIN, HIGH);
delay(100);
digitalWrite(PULSE_PIN, LOW);
delay(100);
digitalWrite(PULSE_PIN, HIGH);
delay(100);
digitalWrite(PULSE_PIN, LOW);
delay(100);
digitalWrite(PULSE_PIN, HIGH);
delay(100);
pixels.setBrightness(20); //set Brightness
pixels.begin();
pixels.show();
pinMode (STROBE_PIN, OUTPUT);
pinMode (RESET_PIN, OUTPUT);
digitalWrite (RESET_PIN, LOW);
digitalWrite (STROBE_PIN, LOW);
delay (1);
digitalWrite (RESET_PIN, HIGH);
delay (1);
digitalWrite (RESET_PIN, LOW);
digitalWrite (STROBE_PIN, HIGH);
delay (1);
}
void loop()
{
counter++;
// clearspectrum();
if (millis() - pwmpulse > 3000){
toggle = !toggle;
digitalWrite(PULSE_PIN, toggle);
pwmpulse = millis();
}
digitalWrite(RESET_PIN, HIGH);
delayMicroseconds(3000);
digitalWrite(RESET_PIN, LOW);
for(int i=0; i < COLUMNS; i++){
digitalWrite(STROBE_PIN, LOW);
delayMicroseconds(1000);
digitalWrite(BAND_SWITCH, (i%2) ? LOW : HIGH); //lower or higher half addresing FSA3157P6X
spectrumValue[i] = analogRead(0);
#ifdef DEBUG
Serial.print(spectrumValue[i]); Serial.write(",");
#endif
if(spectrumValue[i] < 120)spectrumValue[i] = 0;
spectrumValue[i] = constrain(spectrumValue[i], 0, 1023);
spectrumValue[i] = map(spectrumValue[i], 0, 1023, 0, ROWS);
digitalWrite(STROBE_PIN, HIGH);
}
#ifdef DEBUG
Serial.println("");
#endif
for(int j = 0; j < COLUMNS; j++){
for(int i = 0; i < ROWS; i++){
if(i<spectrumValue[j]){
spectrum[i][j].active = 1;
spectrum[i][j].r =0; //COLUMN Color red
spectrum[i][j].g =255; //COLUMN Color green
spectrum[i][j].b =i*32; //COLUMN Color blue
}else{
spectrum[i][j].active = 0;
spectrum[i][j].r =0;
spectrum[i][j].g =0;
spectrum[i][j].b =0;
}
}
if(spectrumValue[j] > peakhold[j].position)
{
peakhold[j].position = spectrumValue[j];
peakhold[j].peakpause = 3; //set peakpause
}
else
{
spectrum[peakhold[j].position][j].active = 1;
spectrum[peakhold[j].position][j].r = 255; //Peak Color red
spectrum[peakhold[j].position][j].g = 0; //Peak Color green
spectrum[peakhold[j].position][j].b = 0; //Peak Color blue
}
}
flushMatrix();
if(counter > 3) { topSinking(); counter=0; } //peak delay
}
void topSinking()
{
for(int j = 0; j < COLUMNS; j++)
{
if(peakhold[j].position > 0 && peakhold[j].peakpause <= 0) peakhold[j].position--;
else if(peakhold[j].peakpause > 0) peakhold[j].peakpause--;
}
}
void clearspectrum()
{
for(int j = 0; j < COLUMNS; j++)
for(int i = 0; i < ROWS; i++)
spectrum[i][j].active = 0;
}
void flushMatrix()
{
for(int j = 0; j < COLUMNS; j++)
{
if( j % 2 != 0)
{
for(int i = 0; i < ROWS; i++)
{
if(spectrum[ROWS - 1 - i][j].active)
{
pixels.setPixelColor(j * ROWS + i, pixels.Color(
spectrum[ROWS - 1 - i][j].r,
spectrum[ROWS - 1 - i][j].g,
spectrum[ROWS - 1 - i][j].b));
}
else
{
pixels.setPixelColor( j * ROWS + i, 0, 0, 0);
}
}
}
else
{
for(int i = 0; i < ROWS; i++)
{
if(spectrum[i][j].active)
{
pixels.setPixelColor(j * ROWS + i, pixels.Color(
spectrum[i][j].r,
spectrum[i][j].g,
spectrum[i][j].b));
}
else
{
pixels.setPixelColor( j * ROWS + i, 0, 0, 0);
}
}
}
}
pixels.show();
}