-
Notifications
You must be signed in to change notification settings - Fork 10
/
MEOOscillate.cpp
62 lines (51 loc) · 1.53 KB
/
MEOOscillate.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
/*
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 <http://github.com/sowbug>.
and Mark Ortiz
and Adafruit
See README for complete attributions.
*/
#include <MEOOscillate.h>
MEOOscillate::MEOOscillate(MEOG35& g35, uint8_t pattern)
: MEOLightProgram(g35, pattern), intensity_(0), pattern_(pattern), colorMain_(0), wait_(5), oscillations_(10), decay_(0.2), step_(0)
{
//g35_.fill_color(0, light_count_, MEOG35::MAX_INTENSITY, COLOR_BLACK);
}
uint32_t MEOOscillate::Do()
{
switch (pattern_ % 4)
{
case 0:
colorMain_ = COLOR(12,12,12);
break;
case 1:
colorMain_ = COLOR(0,0,15);
break;
case 2:
colorMain_ = COLOR(15,0,0);
break;
case 3:
colorMain_ = COLOR(0,15,0);
break;
}
float freq = 1; //oscillations per second
int amplitude = (light_count_ / 2) - 1;
int y;
float time = float(step_) / 100.0;
y = (amplitude * sin(freq * time * 2 * PI) / exp(decay_ * time)) + (light_count_ / 2);
if (step_ == 0)
{
g35_.fill_color(0, light_count_, MEOG35::MAX_INTENSITY, COLOR_BLACK);
}
g35_.fill_color(y, 1, MEOG35::MAX_INTENSITY, colorMain_);
delay(wait_);
g35_.fill_color(y, 1, MEOG35::MAX_INTENSITY, COLOR_BLACK);
step_++;
if (step_ == oscillations_ * 100)
{
step_ = 0;
}
return bulb_frame_;
}