forked from sowbug/G35Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pulse.cpp
35 lines (29 loc) · 923 Bytes
/
Pulse.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
/*
G35: An Arduino library for GE Color Effects G-35 holiday lights.
Copyright © 2011 The G35 Authors. Use, modification, and distribution are
subject to the BSD license as described in the accompanying LICENSE file.
By Mike Tsao <https://github.com/sowbug>.
See README for complete attributions.
*/
#include <Pulse.h>
Pulse::Pulse(G35& g35)
: LightProgram(g35),
count_(1),
sequence_(0) {}
uint32_t Pulse::Do() {
g35_.fill_sequence(0, count_, sequence_, 1, pulser);
if (count_ < light_count_) {
++count_;
} else {
++sequence_;
}
return 1;
}
// static
bool Pulse::pulser(uint16_t sequence, color_t& color, uint8_t& intensity) {
const int PHASE = 32;
const int PULSE_RATE = 2; // Above 1 is glitchy but IMO more attractive.
color = G35::max_color((sequence + PHASE) / (PHASE * 2));
intensity = abs(PHASE - (int)(sequence * PULSE_RATE) % (PHASE + PHASE));
return true;
}