-
Notifications
You must be signed in to change notification settings - Fork 2
/
RandomMarquee.cpp
73 lines (62 loc) · 1.85 KB
/
RandomMarquee.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
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
#include "RandomMarquee.h"
#include "Arduino.h"
#define DEFAULT_MOVE_INTERVAL 250
#define DEFAULT_BRIGHT_INTERVAL 5
#define DEFAULT_SCALE_BRIGHT 0.02
#define DEFAULT_SCALE_DIM 0.01
LED_CONTROLLER_NAMESPACE_USING
RandomMarquee::RandomMarquee() : addColorInterval(DEFAULT_MOVE_INTERVAL),
startIndex(0), brightInterval(DEFAULT_BRIGHT_INTERVAL),
scaleBright(DEFAULT_SCALE_BRIGHT), scaleDim(DEFAULT_SCALE_DIM)
{
setStartColors();
}
RandomMarquee::RandomMarquee(int brightInterval,
float scaleBright, float scaleDim) :
addColorInterval(DEFAULT_MOVE_INTERVAL),
startIndex(0), brightInterval(brightInterval),
scaleBright(scaleBright), scaleDim(scaleDim)
{
setStartColors();
}
void RandomMarquee::setStartColors() {
colors[0] = Color(0xFF0000); // bright Red
colors[1] = Color(0x00FF00); // bright Green
colors[2] = Color(0x0000FF); // bright Blue
colors[3] = Color(0x010000); // faint red
colors[4] = Color(0x800000); // 1/2 red (0x80 = 128 out of 256)
}
bool RandomMarquee::update() {
if (addColorInterval.update()) {
addColorInterval.clearExpired();
advance();
colors[startIndex].setRandom();
// Dim the whole strip, make every fifth color brighter.
float scaleAmount = startIndex % brightInterval == 0 ?
scaleBright : scaleDim;
colors[startIndex] = colors[startIndex].scaled(scaleAmount);
return true;
} else {
return false;
}
}
void RandomMarquee::advance() {
startIndex = startIndex - 1;
if (startIndex < 0) {
startIndex = STRIP_LENGTH - 1;
}
}
void RandomMarquee::setInterval(int interval) {
addColorInterval.setInterval(interval);
}
void RandomMarquee::apply(Color* stripColors) {
int i = 0;
for(int sourceIndex = startIndex; sourceIndex < STRIP_LENGTH;
i++, sourceIndex++)
{
stripColors[i].add(colors[sourceIndex]);
}
for(int sourceIndex = 0; i < STRIP_LENGTH; i++, sourceIndex++) {
stripColors[i].add(colors[sourceIndex]);
}
}