-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRainbowDrop.cpp
More file actions
59 lines (49 loc) · 1.48 KB
/
RainbowDrop.cpp
File metadata and controls
59 lines (49 loc) · 1.48 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
52
53
54
55
56
57
58
59
#include "RainbowDrop.h"
RainbowDrop::RainbowDrop(uint8_t columns, uint8_t rows, uint8_t saturation, CRGB * leds)
: Visualization(columns, rows, 0, saturation, leds)
{
this->rowStep = (int)(255.0 / (float)this->rows);
this->columnStep = (int)(255.0 / (float)this->columns);
this->lastBeat = false;
this->lastBeat2 = false;
this->nextTime = millis();
}
void RainbowDrop::display (unsigned long currentTime, float intensity) {
bool beat = false;
if (intensity > 0.8) {
beat = true;
}
int currentFrame = this->frame % 255;
if (currentTime > this->nextTime) {
// Serial.print(currentTime);
// Serial.print(" - ");
// Serial.print(this->interval);
// Serial.print(" - ");
// Serial.println(this->nextTime);
this->lastBeat2 = this->lastBeat;
if (!beat) {
this->lastBeat = false;
}
if (beat && !this->lastBeat && !this->lastBeat2) {
this->frame += rowStep;
this->lastBeat = true;
} else {
this->frame++;
}
this->nextTime = currentTime + this->interval;
}
uint8_t timeOffset = 255 - currentFrame;
// Serial.println("start");
for (uint8_t y=0; y<this->rows; y++) {
uint8_t rowOffset = this->rowStep * y;
// Serial.println(hue);
for (uint8_t x=0; x<this->columns; x++) {
// uint8_t columnOffset = this->columnStep * x;
uint8_t hue = timeOffset + rowOffset;
CHSV c(hue, this->saturation, 255);
leds[xy2Pos(x, y)] = c;
}
}
// Serial.println("end");
// delay(1000);
}