This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVisualizer.ino
181 lines (165 loc) · 4.07 KB
/
Visualizer.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
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <fix_fft.h>
#include <Servo.h>
#define LCHAN 0
#define greenLed 9
const int channels = 1;
const int xres = 16;
const int yres = 8;
const int gain = 2;
//int decayrate = 2;
int decaytest = 1;
char im[64], data[64];
char Rim[64], Rdata[64];
char data_avgs[32];
float peaks[32];
int valLED;
int i = 0, val, Rval;
int x = 0, y = 0, z = 0;
LiquidCrystal_I2C lcd(0x27, 16, 2);
// ZNAKI
byte v1[8] = {
B00000, B00000, B00000, B00000, B00000, B00000, B00000, B11111
};
byte v2[8] = {
B00000, B00000, B00000, B00000, B00000, B00000, B11111, B11111
};
byte v3[8] = {
B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111
};
byte v4[8] = {
B00000, B00000, B00000, B00000, B11111, B11111, B11111, B11111
};
byte v5[8] = {
B00000, B00000, B00000, B11111, B11111, B11111, B11111, B11111
};
byte v6[8] = {
B00000, B00000, B11111, B11111, B11111, B11111, B11111, B11111
};
byte v7[8] = {
B00000, B11111, B11111, B11111, B11111, B11111, B11111, B11111
};
byte v8[8] = {
B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111
};
void setup() {
lcd.init();
lcd.backlight();
lcd.createChar(1, v1);
lcd.createChar(2, v2);
lcd.createChar(3, v3);
lcd.createChar(4, v4);
lcd.createChar(5, v5);
lcd.createChar(6, v6);
lcd.createChar(7, v7);
lcd.createChar(8, v8);
startup();
}
void startup() {
lcd.clear();
delay(50);
lcd.setCursor(0, 0);
lcd.print("Booting up");
delay(200);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Booting up.");
delay(200);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Booting up..");
delay(200);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Booting up...");
delay(200);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Booting up");
delay(200);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Booting up.");
delay(200);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Booting up..");
delay(200);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Booting up...");
delay(200);
lcd.clear();
delay(500);
lcd.setCursor(0, 0);
lcd.print("SpectrumAnalyzer");
lcd.setCursor(0, 1);
lcd.print(" by revox, 2019");
delay(4500);
}
void loop() {
for (i = 0; i < 64; i++) {
val = ((analogRead(LCHAN) / 4 ) - 128);
data[i] = val;
im[i] = 0;
};
fix_fft(data, im, 6, 0); // Send the data through fft
for (i = 0; i < 32 ; i++) {
data[i] = sqrt(data[i] * data[i] + im[i] * im[i]);
}
for (i = 0; i < 32; i++) {
data_avgs[i] = (data[i]);// + data[i*2+1]);// + data[i*3 + 2]);// + data[i*4 + 3]); // add 3 samples to be averaged, use 4 when yres < 16
data_avgs[i] = constrain(data_avgs[i], 0, 9 - gain); //data samples * range (0-9) = 9
data_avgs[i] = map(data_avgs[i], 0, 9 - gain, 0, yres); // remap averaged values
}
decay(1);
mono();
leds();
} // end loop
void leds() {
valLED = analogRead(LCHAN) * 0.7;
analogWrite(greenLed, valLED);
}
void decay(int decayrate) {
//// reduce the values of the last peaks by 1
if (decaytest == decayrate) {
for (x = 0; x < 32; x++) {
peaks[x] = peaks[x] - 1; // subtract 1 from each column peaks
decaytest = 0;
}
}
decaytest++;
}
void mono() {
for (x = 0; x < xres; x++) { // repeat for each column of the display horizontal resolution
y = data_avgs[x]; // get current column value
z = peaks[x];
if (y > z) {
peaks[x] = y;
}
y = peaks[x];
if (y <= 8) {
lcd.setCursor(x, 0); // clear first row
lcd.print(" ");
lcd.setCursor(x, 1); // draw second row
if (y == 0) {
lcd.print(" "); // save a glyph
}
else {
lcd.write(y);
}
}
else {
lcd.setCursor(x, 0); // draw first row
if (y == 9) {
lcd.write(" ");
}
else {
lcd.write(y - 8); // same chars 1-8 as 9-16
}
lcd.setCursor(x, 1);
lcd.write(8);
}
} // end display
} // end xres