-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStreak.cpp
More file actions
71 lines (61 loc) · 1.69 KB
/
Streak.cpp
File metadata and controls
71 lines (61 loc) · 1.69 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
60
61
62
63
64
65
66
67
68
69
70
71
#include "Streak.h"
Streak::Streak(uint16_t columns,
uint16_t rows,
uint8_t hue,
uint8_t saturation,
CRGB * leds)
: Visualization(columns, rows, hue, saturation, leds)
{
this->length = 0;
this->minLength = 8;
this->maxLength = 16;
this->minInterval = 0;
this->maxInterval = 90;
this->randomHue = false;
this->fade = true;
this->startTime = 0;
}
void Streak::inititalize(unsigned long currentTime) {
// Serial.print("inititalize - ");
// Serial.println(this->frame);
this->frame = 0;
this->startTime = currentTime;
this->interval = random8(this->minInterval, this->maxInterval);
this->column = random8(this->columns);
this->length = random8(this->minLength, this->maxLength);
if (this->randomHue) {
this->setHue(random(256));
}
}
void Streak::display (unsigned long currentTime) {
this->frame = (currentTime - this->startTime)/this->interval;
if (this->frame > (this->rows + this->length)) {
this->inititalize(currentTime);
}
int y = this->frame;
int pos;
for (uint8_t i=0; i<this->length; i++) {
if ((y - i >= 0) && (y - i < this->rows)) {
// this->setLEDColorXY(this->column, y - i);
pos = this->xy2Pos(this->column, y - i);
this->leds[pos] = CHSV(this->hue, this->saturation, this->value);
if (this->fade) {
this->leds[pos].fadeLightBy((256 / this->length) * i);
}
}
}
}
void Streak::setLengthMinMax(uint8_t min, uint8_t max) {
this->minLength = min;
this->maxLength = max;
}
void Streak::setIntervalMinMax(uint8_t min, uint8_t max) {
this->minInterval = min;
this->maxInterval = max;
}
void Streak::setFade(bool on) {
this->fade = on;
}
void Streak::setRandomHue(bool on) {
this->randomHue = on;
}