-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpectrum.cpp
More file actions
51 lines (44 loc) · 1.23 KB
/
Spectrum.cpp
File metadata and controls
51 lines (44 loc) · 1.23 KB
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
#include "Spectrum.h"
Spectrum::Spectrum(uint16_t columns,
uint16_t rows,
uint16_t rowOffset,
uint16_t length,
uint8_t hue,
uint8_t saturation,
bool invert,
uint8_t travel,
CRGB * leds)
: Visualization(columns, rows, hue, saturation, leds) {
this->rowOffset = rowOffset;
this->invert = invert;
this->travel = travel;
this->length = length;
this->threshold = 0.8;
}
void Spectrum::display(float* intensities) {
for (uint8_t y=0; y<this->rows - this->length; y++) {
float intensity = intensities[y + 8]; // THIS IS WHERE WE OFFSET LOWER FREQUENCIES
if (intensity < this->threshold) {
continue;
}
intensity = (intensity - (this->threshold)) / (1 - this->threshold);
uint8_t hue = (this->travel * intensity) + this->hue;
CRGB c = CHSV(hue, this->saturation, 255);
for (uint8_t x=0; x<this->columns; x++) {
if (this->invert) {
leds[this->xy2Pos(x, this->rowOffset - y)] = c;
} else {
leds[this->xy2Pos(x, y + this->rowOffset)] = c;
}
}
}
}
void Spectrum::setTravel(uint8_t travel) {
this->travel = travel;
}
float Spectrum::getThreshold() {
return this->threshold;
}
void Spectrum::setThreshold(float threshold) {
this->threshold = threshold;
}