-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathonoff.cpp
38 lines (28 loc) · 800 Bytes
/
onoff.cpp
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
#include "pixl.h"
using namespace pixl;
namespace pixl {
OnOffVisualization::OnOffVisualization(Input* input, int smoothing)
: Visualization(input, 1),
smoothing_length_(smoothing) {
smoothing_ = new double[smoothing_length_];
for (int i = 0; i < smoothing_length_; i++) {
smoothing_[i] = 0.0;
}
}
OnOffVisualization::~OnOffVisualization() {
delete[] smoothing_;
}
void OnOffVisualization::update() {
double value = input_->getInput();
double sum = 0.0;
for (int i = 0; i < smoothing_length_; i++) {
sum += smoothing_[i];
}
sum += value;
value = sum / (double)(smoothing_length_ + 1);
PushQueue(smoothing_, smoothing_length_, value);
CRGB color = CRGB::Blue;
color.fadeToBlackBy(255 - (255 * value));
viz_[0] = color;
}
} // end namespace pixl