forked from sowbug/G35Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpookyFlicker.cpp
34 lines (28 loc) · 984 Bytes
/
SpookyFlicker.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
/*
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 <SpookyFlicker.h>
SpookyFlicker::SpookyFlicker(G35& g35) : LightProgram(g35) {
intensities_ = static_cast<uint8_t*>(malloc(light_count_ * sizeof(uint8_t)));
deltas_ = static_cast<int8_t*>(malloc(light_count_ * sizeof(int8_t)));
for (uint8_t i = 0; i < light_count_; ++i) {
intensities_[i] = rand();
deltas_[i] = rand() % 5 - 2;
}
g35_.fill_color(0, light_count_, 255, COLOR_BLACK);
}
SpookyFlicker::~SpookyFlicker() {
free(intensities_);
free(deltas_);
}
uint32_t SpookyFlicker::Do() {
for (int i = 0; i < light_count_; ++i) {
g35_.set_color(i, intensities_[i], COLOR_ORANGE);
intensities_[i] += deltas_[i];
}
return 10;
}